SetFocus on Form

R

Ray Hogan

Hi,
I have Command Button on a Form (frmRegister) to open another Form
(frmResort).

Private Sub cmdResortForm_Click()
On Error GoTo Err_cmdResortForm_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmResort"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdResortForm_Click:
Exit Sub

Err_cmdResortForm_Click:
MsgBox Err.Description
Resume Exit_cmdResortForm_Click

End Sub

I then have another Command Button to close and return to frmRegister.

Private Sub cmdCloseForm_Click()
On Error GoTo Err_cmdCloseForm_Click

DoCmd.Requery
DoCmd.Close acForm, "frmResort"
DoCmd.OpenForm "frmRegister", , , , , , "Resort"

Exit_cmdCloseForm_Click:
Exit Sub

Err_cmdCloseForm_Click:
MsgBox Err.Description
Resume Exit_cmdCloseForm_Click

End Sub
In support of this I have the following code on frmRegister Open.
Private Sub Form_Open(Cancel As Integer)
If Me.OpenArgs = "Resort" Then
Me![cmdResort].SetFocus
End If
End Sub
How do I set out this code to set Focus to cmbResort on frmRegister when I
close frmResort.
Thanking in anticipation.
Rayh
 
V

Van T. Dinh

Since you didn't close the frmRegister, when you close the
frmResort and "re-open" the frmRegister, Access doesn't
open it (hence the Open Event doesn't fire). You simply
re-activate the frmRegister in this case.

Try (***untested***):
...
DoCmd.Requery
DoCmd.Close acForm, "frmResort"
DoCmd.OpenForm "frmRegister"
DoEvents
Forms!frmRegister![cmdResort].SetFocus
...

HTH
Van T. Dinh
MVP (Access)
 

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