Closing a form

ekta

Registered User.
Local time
Today, 17:43
Joined
Sep 6, 2002
Messages
160
I have a search form which passes the criteria in a query and opens the form frmKeyWordResults when I click on Perform Search button. I want to close the search when when Perform search button is clicked. I tried to put DoCmd.Close in my code but then my search doesn't work properly. Where should I place it to close the form.

Private Sub Command6_Click()
On Error GoTo Err_Command6_Click

Dim stDocName As String
Dim stLinkCriteria As String
'Docmd.Close
stDocName = "frmKeyWordResults"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command6_Click:
Exit Sub

Err_Command6_Click:
MsgBox Err.Description
Resume Exit_Command6_Click

End Sub
 
Try putting the following after the docmd.openform statement.

docmd.closeform "yoursearchform"


Andy
 
Doesn't work. It tells me "Type mismatch"
 
Just noticed that in your code your have

Dim as stlinkcriteria

but there is no statement defining the strlinkcriteria
This might be what's causing the type mismatch.

Andy
 
You need to add a line of code.

example:

stlinkcriteria = "criteria to set this string".

Andy
 
I am sorry. Not very good with vb.

stlinkcriteria = "criteria to set this string".

What do you mean by this?
 
Couldn't say without looking at your forms.
But the link criteria is say for example:

strlinkcriteria = "[fieldname] = forms!formname!fieldname"

How do pass the search criteria on the form to the query?

No my best topic, but I will try to help.

Andy
 
ok I have unbound fields on my form which I want users to search. I have a query set up with all these fields and in the criteria for the query I use something like this

Like "*" & IIf([Forms]![frmOppSearch]![Name]<>"",[Forms]![frmOppSearch]![Name],"*" & "*") & "*"

The search results are displayed on a form whose record source is set to this query
 
Last edited:
I figured it. The code below works

Thanx for your help

Private Sub Command6_Click()
On Error GoTo Err_Command6_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmKeyWordResults"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, "frmOppSearch"

Exit_Command6_Click:
Exit Sub

Err_Command6_Click:
MsgBox Err.Description
Resume Exit_Command6_Click

End Sub
 
No Worries . Glad to see you managed it.

Sorry I haven't been that much help.

Cheers
Andy
 

Users who are viewing this thread

Back
Top Bottom