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).]
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).]