Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access 2007 Autofill questions

Status
Not open for further replies.

punky001

Programmer
Oct 1, 2007
34
US
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.
 
Any ideas anyone?? Please - I'll try any suggestions....
 
Thanks Hap007....
It runs now without error...but only dups 2 of the 5 fields - fields 1 and 5 - fields 2,3,4 are not duped.
 
Thanks again Hap007 - you found the problem. The last issue was my fault .... runs great now!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top