Go to next record or close

T

Tara

I have a form that displays client data. On the form is a command button to
take the user to the next record. What I'd like to have happen is for the
form close when the user clicks the command button but there are no
additional records to display. Here's the code currently:

Private Sub CmdTransferred_Click()
On Error GoTo Err_CmdTransferred_Click

Dim stDocName As String

stDocName = "qupReply"
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.GoToRecord , , acNext



Exit_CmdTransferred_Click:
Exit Sub

Err_CmdTransferred_Click:
MsgBox Err.Description
Resume Exit_CmdTransferred_Click

End Sub

Thanks!
 
A

AccessVandal via AccessMonster.com

You can try something like this.

Private Sub CmdTransferred_Click()
On Error GoTo Err_CmdTransferred_Click

‘first, goto next record
DoCmd.GoToRecord , , acNext
'if new record, close form
If Me.NewRecord Then
DoCmd.Close acForm, Me.Name
Else
'if not, do nothing
End If

Set rs = Nothing

Exit_CmdTransferred_Click:
Exit Sub

Err_CmdTransferred_Click:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_CmdTransferred_Click

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top