Thank you so much for the explanations on the quotation marks.
Now I know how they work.
If you have a minute I'm still having trouble with parameter dialog box.
I have an OpenForm button on a main form. When I clicked on it a Parameter Value Dialog Box pops up on the main form and prompted me to enter a value for a variable in the subform. I clicked on O.K. without enter a value the subform opens up.
Why is it trying to obtain a value in the subform before it opens up?
I didn't include the filter criteria in the OpenForm method. This is what I wrote in the OpenForm button to open the subform:
It sounds like you misspelled a column name in your query. Look at the query in your subform and make sure that the fields on the form that reference columns in the query are spelled correctly. Check you parent and child link fileds. The parameter dialog box should tell you what parameter it is looking for so that shold help you narrow it down.
I checked the field names and they are fine.
Can I supply you with a little more information on the problem?
The parameter prompt does appear in the subform when click on directly.
CmdSearch is the Search button on the subform. When the button is clicked it compares the value entered in the textbox txtSearchValue with qrySearch. The textbox is also located in the subform and the searchVal variable is used to store the entered value. The searchVal is the parameter value prompting by the dialog box.
The problem seems to be on line #5, but I can’t see why?
-The value entered in txtSearchValue is being stored into searchVal variable.
-SQL statement(line #6) was executed and a record was found and displayed.
Private Sub cmdSearch_Click()
Dim DB As Database
Dim QD As QueryDef
Dim searchVal As String
Dim MyRecordSource As String
searchVal = Me![txtSearchValue]
MyRecordSource = "SELECT * FROM qrySearch WHERE qrySearch.poNum = '" & searchVal & "';"
Me.RecordSource = MyRecordSource
Set DB = DBEngine.Workspaces(0).Databases(0)
On Error Resume Next
On Error GoTo 0
Set QD = DB.CreateQueryDef("qryResults", MyRecordSource)
If you can help I would appreciated it.
The problem is fixed.
I had the SQL statement containing the searchVal as the Recordsource of the subform, but since it is not declared @ the main form when I clicked on the command to open the subform the parameter dialog box popped up.
Thank you very much for your time and effort to help me.
You Have a Nice Day!