davegillian
New member
- Local time
- Today, 10:35
- Joined
- Apr 13, 2006
- Messages
- 9
I have a form that filters certain records out of a table "Customer Details" in my database via the Y/N field Checked where the value is No.
I want a command button on the form that will run a macro that will update the Checked value to Yes and then move to the next record (displaying it in the same form) until the last form is displayed at which point I would like the value to be updated and the form to be closed.
Using the GoToRecord - Next action in my Macro I can achieve the first part but when the last record is reached an error message is displayed.
I think I can get around this by using the EOF command in Visual Basic but I am new to this language and the code I've written is clearly not correct!
Could anyone suggest a correction to my code or another method for this?
Cheers,
Dave
Function Mark_As_Checked___Move_To_Next_Record()
On Error GoTo Mark_As_Checked___Move_To_Next_Record_Err
DoCmd.OpenQuery "Mark As Checked", acViewNormal, acEdit
Dim stDocName As String
Dim Unchecked As Recordset
Set Unchecked = [new training db].OpenRecordset(SelSQl = "SELECT [Customer Details].* FROM [Customer Details] WHERE ((([Customer Details].Checked)=No));", dbOpenDynaset)
stDocName = "Mark As Checked"
Do Until Unchecked.EOF
DoCmd.OpenQuery stDocName
DoCmd.GoToRecord , "", acNext
Loop
stDocName = "Customer Details Complete"
DoCmd.Close stDocName
Mark_As_Checked___Move_To_Next_Record_Exit:
Exit Function
Mark_As_Checked___Move_To_Next_Record_Err:
MsgBox Error$
Resume Mark_As_Checked___Move_To_Next_Record_Exit
End Function
I want a command button on the form that will run a macro that will update the Checked value to Yes and then move to the next record (displaying it in the same form) until the last form is displayed at which point I would like the value to be updated and the form to be closed.
Using the GoToRecord - Next action in my Macro I can achieve the first part but when the last record is reached an error message is displayed.
I think I can get around this by using the EOF command in Visual Basic but I am new to this language and the code I've written is clearly not correct!
Could anyone suggest a correction to my code or another method for this?
Cheers,
Dave
Function Mark_As_Checked___Move_To_Next_Record()
On Error GoTo Mark_As_Checked___Move_To_Next_Record_Err
DoCmd.OpenQuery "Mark As Checked", acViewNormal, acEdit
Dim stDocName As String
Dim Unchecked As Recordset
Set Unchecked = [new training db].OpenRecordset(SelSQl = "SELECT [Customer Details].* FROM [Customer Details] WHERE ((([Customer Details].Checked)=No));", dbOpenDynaset)
stDocName = "Mark As Checked"
Do Until Unchecked.EOF
DoCmd.OpenQuery stDocName
DoCmd.GoToRecord , "", acNext
Loop
stDocName = "Customer Details Complete"
DoCmd.Close stDocName
Mark_As_Checked___Move_To_Next_Record_Exit:
Exit Function
Mark_As_Checked___Move_To_Next_Record_Err:
MsgBox Error$
Resume Mark_As_Checked___Move_To_Next_Record_Exit
End Function