"close" command

M

mcjanes

I have a simple Search dialog box with a text box...the user types in a
student number, clicks a command button and the student's information
pops up in the Student form.

How do I get the dialog box to close when the user clicks the command
button? I know I have to use this code in the command button's OnClick
event, but where does it go?:

' Close Dialog Box.
DoCmd.Close

Here is the code for the OnClick event:

Private Sub cmdSearchStudent_Click()
On Error GoTo Err_cmdSearchStudent_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frm_Students"

stLinkCriteria = "[s_StudentID]=" & "'" & Me![txtSearchForm] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdSearchStudent_Click:
Exit Sub

Err_cmdSearchStudent_Click:
MsgBox Err.Description
Resume Exit_cmdSearchStudent_Click

End Sub
 
L

lgalumbres

Hi,

Your on the right track, you were just missing parameters for the
DoCmd.Close method. Try this.....

Private Sub cmdSearchStudent_Click()
On Error GoTo Err_cmdSearchStudent_Click

Dim stDialogBoxName As String ' Variable for your dialog box.
Dim stDocName As String
Dim stLinkCriteria As String

stDialogBoxName = "TheNameOfYourDialogBoxGoesHere"
stDocName = "frm_Students"

stLinkCriteria = "[s_StudentID]=" & "'" & Me![txtSearchForm] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

DoCmd.Close acForm, stDialogBoxName ' This closes the dialog box.

Exit_cmdSearchStudent_Click:
Exit Sub

Err_cmdSearchStudent_Click:
MsgBox Err.Description
Resume Exit_cmdSearchStudent_Click

End Sub

Cheers!
- Lem
 
M

McJanes

Ok, so I punched in what you said: (my dialog box is named
SearchDialog:)

Private Sub cmdSearchStudent_Click()
On Error GoTo Err_cmdSearchStudent_Click

Dim stSearchDialog As String
Dim stDocName As String
Dim stLinkCriteria As String

stDialogBoxName = "SearchDialog"
stDocName = "frm_Students"

stLinkCriteria = "[s_StudentID]=" & "'" & Me![txtSearchForm] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

DoCmd.Close acForm, stSearchDialog

Exit_cmdSearchStudent_Click:
Exit Sub

Err_cmdSearchStudent_Click:
MsgBox Err.Description
Resume Exit_cmdSearchStudent_Click

End Sub

Now when I do a search, the correct information still pops up in the
Students form, but I get a dialog box saying "This action requires an
Object Name argument".

thoughts?


Hi,

Your on the right track, you were just missing parameters for the
DoCmd.Close method. Try this.....

Private Sub cmdSearchStudent_Click()
On Error GoTo Err_cmdSearchStudent_Click

Dim stDialogBoxName As String ' Variable for your dialog box.
Dim stDocName As String
Dim stLinkCriteria As String

stDialogBoxName = "TheNameOfYourDialogBoxGoesHere"
stDocName = "frm_Students"

stLinkCriteria = "[s_StudentID]=" & "'" & Me![txtSearchForm] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

DoCmd.Close acForm, stDialogBoxName ' This closes the dialog box.

Exit_cmdSearchStudent_Click:
Exit Sub

Err_cmdSearchStudent_Click:
MsgBox Err.Description
Resume Exit_cmdSearchStudent_Click

End Sub

Cheers!
- Lem


I have a simple Search dialog box with a text box...the user types in a
student number, clicks a command button and the student's information
pops up in the Student form.

How do I get the dialog box to close when the user clicks the command
button? I know I have to use this code in the command button's OnClick
event, but where does it go?:

' Close Dialog Box.
DoCmd.Close

Here is the code for the OnClick event:

Private Sub cmdSearchStudent_Click()
On Error GoTo Err_cmdSearchStudent_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frm_Students"

stLinkCriteria = "[s_StudentID]=" & "'" & Me![txtSearchForm] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdSearchStudent_Click:
Exit Sub

Err_cmdSearchStudent_Click:
MsgBox Err.Description
Resume Exit_cmdSearchStudent_Click

End Sub
 
L

lgalumbres

I have no idea what thats about. DoCmd.Close has the following
arguments/parameters {objecttype}, {objectname}, {Save} being
optional. And we've pass {objecttype} and {objectname} so it should
work.

Try adding the save argument. For example:

DoCmd.Close acForm, stSearchDialog, acSaveNo

Or you can try directly putting the search dialog box name into the
method rather than storing it into a string variable and passing it to
the method. For example:

DoCmd.Close acForm, "SearchDialog", acSaveNo

If none of those work, click on the link below. Its an article I found
on Microsofts KB that might be related to the problem you are having.
Good luck!

http://support.microsoft.com/kb/197950/EN-US/

Cheers!
- Lem
Ok, so I punched in what you said: (my dialog box is named
SearchDialog:)

Private Sub cmdSearchStudent_Click()
On Error GoTo Err_cmdSearchStudent_Click

Dim stSearchDialog As String
Dim stDocName As String
Dim stLinkCriteria As String

stDialogBoxName = "SearchDialog"
stDocName = "frm_Students"

stLinkCriteria = "[s_StudentID]=" & "'" & Me![txtSearchForm] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

DoCmd.Close acForm, stSearchDialog

Exit_cmdSearchStudent_Click:
Exit Sub

Err_cmdSearchStudent_Click:
MsgBox Err.Description
Resume Exit_cmdSearchStudent_Click

End Sub

Now when I do a search, the correct information still pops up in the
Students form, but I get a dialog box saying "This action requires an
Object Name argument".

thoughts?


Hi,

Your on the right track, you were just missing parameters for the
DoCmd.Close method. Try this.....

Private Sub cmdSearchStudent_Click()
On Error GoTo Err_cmdSearchStudent_Click

Dim stDialogBoxName As String ' Variable for your dialog box.
Dim stDocName As String
Dim stLinkCriteria As String

stDialogBoxName = "TheNameOfYourDialogBoxGoesHere"
stDocName = "frm_Students"

stLinkCriteria = "[s_StudentID]=" & "'" & Me![txtSearchForm] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

DoCmd.Close acForm, stDialogBoxName ' This closes the dialog box.

Exit_cmdSearchStudent_Click:
Exit Sub

Err_cmdSearchStudent_Click:
MsgBox Err.Description
Resume Exit_cmdSearchStudent_Click

End Sub

Cheers!
- Lem


I have a simple Search dialog box with a text box...the user types in a
student number, clicks a command button and the student's information
pops up in the Student form.

How do I get the dialog box to close when the user clicks the command
button? I know I have to use this code in the command button's OnClick
event, but where does it go?:

' Close Dialog Box.
DoCmd.Close

Here is the code for the OnClick event:

Private Sub cmdSearchStudent_Click()
On Error GoTo Err_cmdSearchStudent_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frm_Students"

stLinkCriteria = "[s_StudentID]=" & "'" & Me![txtSearchForm] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdSearchStudent_Click:
Exit Sub

Err_cmdSearchStudent_Click:
MsgBox Err.Description
Resume Exit_cmdSearchStudent_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