Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

QueryDefs and Parameters

Status
Not open for further replies.

tbclbd

Programmer
May 6, 2002
33
US
I have an application in which I have defined a query, and am trying to execute it using querydefs and parameters (The code follows below). If I open the query in design view, and manually enter the selection criteria, I receive the correct results, but, when I try to run the query from code passing the criteria from a form, I keep getting a data type mismatch error. I've checked the field names and types, and all seems to be ok.

Does anyone have any suggestions?

Dim docName As String
Dim ctl As control
Dim blnValid As Boolean
Dim dbs As Database
Dim qdf As QueryDef
Dim prm As Parameter
Dim tdf As TableDef
Dim lngCount As Long
Dim NewName As String
Set dbs = CurrentDb()

dbs.Execute ("DELETE * FROM " & conWorkTable & ";")
Select Case fraAddressType
Case 1 ' BillWho = "B"
If fraCriteria = 1 Then
Set qdf = dbs.QueryDefs![MailMerge -- Owner Account]
End If

Case 2 ' BillWho = "S"
If fraCriteria = 1 Then
Set qdf = dbs.QueryDefs![MailMerge -- Owner and Service Book]
End Select

For Each prm In qdf.Parameters
prm.value = Eval(prm.Name)
Next prm
qdf.Execute
qdf.Close
 
Just a guess but the statement

prm.value = Eval(prm.Name)

looks like it's going to take the name of each parameter and assign that to the prm.value as a text string. If some of your parameters should be numerics or booleans then this will cause a type mismatch. You also said that you were "... passing the criteria from a form ...". I don't see that happening here.

I also notice that under "Case 2" you seem to be missing an "End If"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top