I have used an autofill module that works great in Access 97 and 2003. I cannot get it to work in 2007. Here's the module code:
Function AutoFillNewRecord(F As Form)
Dim RS As DAO.Recordset, C As Control
Dim FillFields As String, 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
' Get 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 set this to run on the form property ONCurrent property as follows:
=AutoFillNewRecord([Forms]![Customers])
I then add a text box to the form with the following properties:
Name: AutoFillNewRecordFields
Visible: NO
DefaultValue:Field1:Field2: (fields to be autofilled or leave blank for all)
When I open the form to run I get the following error:
"The expression ON Current you entered as the event property setting produced the following error: Type mismatch.
- expression may not result in the name of a macro, the name of a user-defined function or Event procedure OR there may have been an error evaluating the function, event or macro.
Any ideas why this won't work in 2007? I really used this alot in 2003 and hate to lose the ability to run it.
Function AutoFillNewRecord(F As Form)
Dim RS As DAO.Recordset, C As Control
Dim FillFields As String, 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
' Get 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 set this to run on the form property ONCurrent property as follows:
=AutoFillNewRecord([Forms]![Customers])
I then add a text box to the form with the following properties:
Name: AutoFillNewRecordFields
Visible: NO
DefaultValue:Field1:Field2: (fields to be autofilled or leave blank for all)
When I open the form to run I get the following error:
"The expression ON Current you entered as the event property setting produced the following error: Type mismatch.
- expression may not result in the name of a macro, the name of a user-defined function or Event procedure OR there may have been an error evaluating the function, event or macro.
Any ideas why this won't work in 2007? I really used this alot in 2003 and hate to lose the ability to run it.