autofill function - type mismatch error (repost from "Forms" section) (1 Viewer)

snorf3

Registered User.
Local time
Today, 12:00
Joined
May 25, 2001
Messages
45
I'm trying to get the fields (text and boolean) on my form to autofill when a new record is opened. I would like each field to retain whatever value was in the previous record until the user decides to change the value. I've been trying to use the following code but keep getting error messages. Here's the gist of it.

module code:

Function AutoFillNewRecord(F As Form)

Dim rs As DAO.Recordset, C As Control
Dim FillFields As String, FillAllFields As Boolean

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
--------------------------------------------


I then have an unbound text box on my form, set to not visible, named "AutoFillNewRecordFields". On my form's OnCurrent Property I have the following:

=AutoFillNewRecord([Forms]![frmClinical])

The error message I get is this:

The expression OnCurrent you entered as the event property setting produced the following error: Type mismatch.
*The expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure].
*There may have been an error evaluating the function, event, or macro.

I've been asking this question for a while and am desperately seeking an answer!!! Anyone who can help, your input is very much appreciated!!! Thanks!



[This message has been edited by snorf3 (edited 06-19-2001).]
 

jfi

Registered User.
Local time
Today, 12:00
Joined
Jan 28, 2000
Messages
22
Perhaps this is too simplistic, or doesn't do exactly what you want. When I wanted to create new records that had the same values as the record on my screen, I just made a command button and used the wizard to make it a "copy record" button. That creates a new record and copies all the values of whatever record you were looking at into it.

-Joshua
 

snorf3

Registered User.
Local time
Today, 12:00
Joined
May 25, 2001
Messages
45
Rich -- thanks!!!! It works like a charm now! Can't believe it was something that simple!
 

Users who are viewing this thread

Top Bottom