Douglas Cummings
asked on
Return to Next Record On Datasheet
I have a form containing a datasheet sub form used for processing records. When the user double-clicks on a record, it loads the corresponding customer form. Once processing has been completed, the underlying record from the datasheet is deleted and the sub form is refreshed. However, once refreshed, the pointer goes to the first record. I want it to go to the record just after the one just processed.
There are two triggers that cause the record in the datasheet to be deleted. If certain values are entered in the customer record, it deletes the record in the datasheet upon closing the customer form. The other method is clicking a 'Processed' button on the form containing the datasheet.
So, I need to add code in both locations or at the point that the form regains focus. Can someone help me with the VB code to accomplish this?
Thanks.
There are two triggers that cause the record in the datasheet to be deleted. If certain values are entered in the customer record, it deletes the record in the datasheet upon closing the customer form. The other method is clicking a 'Processed' button on the form containing the datasheet.
So, I need to add code in both locations or at the point that the form regains focus. Can someone help me with the VB code to accomplish this?
Thanks.
ASKER
Thanks for responding.
However, I am still getting the same result. When the customer form closes, the record pointer goes to the first record on the datasheet.
Here is the code on the double-click event on the datasheet subform:
Dim lngId As Long
Dim rs As DAO.Recordset
lngId = DMin("NoEmailId", "qryNoEmail", "NoEmailId > " & Me.NoEmailId)
DoCmd.OpenForm "frmCustomers", , , "CustomerId = " & Me.CustomerId
Set rs = Me.RecordsetClone
rs.FindFirst "NoEmailId = " & lngId
Me.Bookmark = rs.Bookmark
Here is the code on the close event for the customer form:
Dim CustId As Long
CustId = Me.CustomerId
DoCmd.Close acForm, "frmCustomers"
If CurrentProject.AllForms("f rmNoEmail" ).IsLoaded Then
DoCmd.SetWarnings False
DoCmd.RunSQL "Update dbo_tblNoEmail Set ProcessedBy = '" & fOSUserName() & _
"', Processed = True, DateProcessed = #" & Date & "# Where CustomerId = " & _
CustId & ";"
DoCmd.SetWarnings True
Forms!frmNoEmail!frmNoEmai lSF.Form.R equery
End If
Doug
However, I am still getting the same result. When the customer form closes, the record pointer goes to the first record on the datasheet.
Here is the code on the double-click event on the datasheet subform:
Dim lngId As Long
Dim rs As DAO.Recordset
lngId = DMin("NoEmailId", "qryNoEmail", "NoEmailId > " & Me.NoEmailId)
DoCmd.OpenForm "frmCustomers", , , "CustomerId = " & Me.CustomerId
Set rs = Me.RecordsetClone
rs.FindFirst "NoEmailId = " & lngId
Me.Bookmark = rs.Bookmark
Here is the code on the close event for the customer form:
Dim CustId As Long
CustId = Me.CustomerId
DoCmd.Close acForm, "frmCustomers"
If CurrentProject.AllForms("f
DoCmd.SetWarnings False
DoCmd.RunSQL "Update dbo_tblNoEmail Set ProcessedBy = '" & fOSUserName() & _
"', Processed = True, DateProcessed = #" & Date & "# Where CustomerId = " & _
CustId & ";"
DoCmd.SetWarnings True
Forms!frmNoEmail!frmNoEmai
End If
Doug
--- >> DoCmd.OpenForm "frmCustomers", , , "CustomerId = " & Me.CustomerId
Take another look at my earlier post :-)
You need to open the form in dialog mode. This temporarily suspends code execution in the calling block of code... and importantly resumes code execution when the form closes.
Without using dialog mode, the code following the OpenForm is ignored.
So change that line to this:
DoCmd.OpenForm "frmCustomers", , , "CustomerId = " & Me.CustomerId,,, acDialog
Take another look at my earlier post :-)
You need to open the form in dialog mode. This temporarily suspends code execution in the calling block of code... and importantly resumes code execution when the form closes.
Without using dialog mode, the code following the OpenForm is ignored.
So change that line to this:
DoCmd.OpenForm "frmCustomers", , , "CustomerId = " & Me.CustomerId,,, acDialog
Actually - I think I'm messing up with the number of commas. The window Mode might be the fifth argument:
DoCmd.OpenForm "frmCustomers", , , "CustomerId = " & Me.CustomerId ,, acDialog
But my preference is to use named arguments to avoid the confusion with the commas:
DoCmd.OpenForm "frmCustomers", , , "CustomerId = " & Me.CustomerId ,, acDialog
But my preference is to use named arguments to avoid the confusion with the commas:
DoCmd.OpenForm "frmCustomers", WhereCondition := "CustomerId = " & Me.CustomerId, WindowMode := acDialog
ASKER
Thanks, that worked. Sorry I missed the "acDialog" as I already had the code to open the form.
One more question, I have a processed button on the parent form as an alternative to opening the form. The existing code is:
DoCmd.SetWarnings False
DoCmd.RunSQL "Update dbo_tblNoEmail Set ProcessedBy = '" & fOSUserName() & _
"', Processed = True, DateProcessed = #" & Date & "# Where CustomerId = " & _
CustId & ";"
DoCmd.SetWarnings True
Me.frmNoEmailSF.Requery
What code would I use on the on-click event for that control that would accomplish the same result?
One more question, I have a processed button on the parent form as an alternative to opening the form. The existing code is:
DoCmd.SetWarnings False
DoCmd.RunSQL "Update dbo_tblNoEmail Set ProcessedBy = '" & fOSUserName() & _
"', Processed = True, DateProcessed = #" & Date & "# Where CustomerId = " & _
CustId & ";"
DoCmd.SetWarnings True
Me.frmNoEmailSF.Requery
What code would I use on the on-click event for that control that would accomplish the same result?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks again. You went the extra mile on this one. If I could award you double points I would.
:-)
Glad to help,
Glad to help,
generally (read the inline comments in the example below) -
Open in new window
That's it in its simplest form... you can/should embellish that with error handling and handling for special cases like no exisitng "next" record.