I'm trying to loop through all records on an open form until the last record "ZZZZZ", using a Select query and update query to update a different table based on fields on the selected record on a form. I am trying to run the module from a button on the form that lists the eSearchTerms. It won't loop.
???
Option Compare Database
'------------------------------------------------------------
' mcrGoToNextxSearchTerm
'
'------------------------------------------------------------
Function mcrGoToNextxSearchTerm()
Dim rs As DAO.Recordset
DoCmd.SetWarnings False
DoCmd.SelectObject acForm, "xSearchTerms", False
On Error GoTo mcrGoToNextxSearchTerm_Err
'DoCmd.SetWarnings False -- should this go here or above?
'DoCmd.SelectObject acForm, "xSearchTerms", False -- should this go here or above
'Go to next record on form
Forms![xSearchTerms]![txt_eSearchTerm].SetFocus
DoCmd.GoToRecord , "", acNext
'Does the value in txt_eSearchTerm = "ZZZZZZ"; if yes, exit; if not, proceed
Do Until Forms![xSearchTerms]![txt_eSearchTerm] = "ZZZZZ"
'Open query using select statement created from form field [eSearchTerm]
DoCmd.OpenQuery "Sheet3 Query1", acViewNormal, acReadOnly
DoCmd.OpenQuery "qryUPDATE_BankItems", acViewNormal, acReadOnly
DoCmd.Close acQuery, "qryUPDATE_BankItems"
DoCmd.Close acQuery, "Sheet3 Query1"
Loop
DoCmd.SetWarnings True
Exit Function
mcrGoToNextxSearchTerm_Exit:
Exit Function
mcrGoToNextxSearchTerm_Err:
MsgBox Error$
Resume mcrGoToNextxSearchTerm_Exit
End Function
???
Option Compare Database
'------------------------------------------------------------
' mcrGoToNextxSearchTerm
'
'------------------------------------------------------------
Function mcrGoToNextxSearchTerm()
Dim rs As DAO.Recordset
DoCmd.SetWarnings False
DoCmd.SelectObject acForm, "xSearchTerms", False
On Error GoTo mcrGoToNextxSearchTerm_Err
'DoCmd.SetWarnings False -- should this go here or above?
'DoCmd.SelectObject acForm, "xSearchTerms", False -- should this go here or above
'Go to next record on form
Forms![xSearchTerms]![txt_eSearchTerm].SetFocus
DoCmd.GoToRecord , "", acNext
'Does the value in txt_eSearchTerm = "ZZZZZZ"; if yes, exit; if not, proceed
Do Until Forms![xSearchTerms]![txt_eSearchTerm] = "ZZZZZ"
'Open query using select statement created from form field [eSearchTerm]
DoCmd.OpenQuery "Sheet3 Query1", acViewNormal, acReadOnly
DoCmd.OpenQuery "qryUPDATE_BankItems", acViewNormal, acReadOnly
DoCmd.Close acQuery, "qryUPDATE_BankItems"
DoCmd.Close acQuery, "Sheet3 Query1"
Loop
DoCmd.SetWarnings True
Exit Function
mcrGoToNextxSearchTerm_Exit:
Exit Function
mcrGoToNextxSearchTerm_Err:
MsgBox Error$
Resume mcrGoToNextxSearchTerm_Exit
End Function