-
Trouble making code in M.S. Article 210236 work to carry over data to a new record
Hi,
Been trying to incorporate the code in M.S. Knowledge
base article- 210236 to carry over data from a previous
records into a new record.
Have a database of students that contains which classes
they have attended. What I want be able to do is located a
student record, then when I click on the "ADD" button the
fields on the form default with the data contained in the
previous record that was displayed. Can't seem to make
this work.
When I try the logic contained in article # 210236 it
always seems to pick up the data in the last record after
it performs the RS.MoveLast line of code.
Here is the main code contained in the article:
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|