snorf3
06-12-2001, 09:29 AM
I've been trying to use this code to get my forms to autofill based on the previous record. My data types include boolean, integer, and text. How do I modify the following code to reflect this? I'm just a very early beginner with coding!
This is what I have now but it is not working:
Dim FillFields As String, FillAllFields As Integer
charityg
06-12-2001, 09:50 AM
Dim FillFields As String
dim FillAllFields As Integer
snorf3
06-12-2001, 12:27 PM
Thanks for the suggestion. Unfortunately, it doesn't seem to make any difference. I'm still getting a "type mismatch" error message.
Any other thoughts?
charityg
06-13-2001, 05:11 AM
What is the rest of your code?
snorf3
06-13-2001, 07:33 AM
Here's what I have right now. It came from the MS help article Q210236. The form I am trying to use this on is also embedded as a subform within another form. Does that make any difference?
-------------------------------
Option Compare Database
Option Explicit
Function AutoFillNewRecord(F As Form)
Dim RS As DAO.Recordset, C As Control
Dim FillFields As String
Dim FillAllFields As Integer
On Error Resume Next
'Exit if not on the new record.
If Not F.NewRecord Then Exit Function
'Goto the last record of the form recordset (to autofill form).
Set RS = F.RecordsetClone
RS.MoveLast
'Exit if you cannot move to the last record (no records).
If Err <> 0 Then Exit Function
'Fet the list of fields to autofill
FillFields = ";" & F![AutoFillNewRecordFields] & ";"
'If there is no criteria field, then set flag indicating ALL fields should be autofilled.
FillAllFields = Err <> 0
F.Painting = False
'Visit each field on the form.
For Each C In F
'fill the field if ALL fields are to be filled OR if the
'...ControlSource field can be found in the FillFields list.
If FillAllFields Or InStr(FillFields, ";" & (C.Name) & ";") > 0 Then
C = RS(C.ControlSource)
End If
Next
F.Painting = True
End Function
D-Fresh
06-13-2001, 08:37 AM
It looks like FillAllFields should be a boolean value. Try this..
dim FillAllFields As boolean
snorf3
06-13-2001, 12:41 PM
D-Fresh: Thanks but I tried it and it still doesn't work.
Do you think the problem is strictly with the data types? Or does having this function on a subform maybe cause some problem with recognition of stuff?