I am getting an error with the following code:
When I run I get "Run-time error '3061' Too few paramaters expected 2" In reference to the db.OpenRecordset() line at the end. The function is called from a button event with:
and table is also a string variable
Code:
Public Function QueryExists(queryName As String) As Boolean
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Set db = CurrentDb
QueryExists = False
For Each qdf In db.QueryDefs
If qdf.Name = queryName Then
QueryExists = True
Exit Function
End If
Next qdf
End Function
Public Function FindCityState(table As String, cityField As String, stateField As String, _
cityOutputField As Variant, stateOutputField As Variant)
Dim db As DAO.Database 'declare variable to hold db/workspace name
Dim qdf As DAO.QueryDef 'declare variable to hold query info
Dim rs As DAO.Recordset 'declare variable to reference query result table
Dim strSQL As String 'declare sql string variable
Dim queryName As String 'declare query name variable
Set db = CurrentDb 'Set name of database
queryName = "tempQuery" 'Set name of temporary query
strSQL = "SELECT DISTINCT [3 CITY],[3 ST] " & _
"FROM " & table & " " & _
"WHERE " & cityField & "=" & table & ".[5 CITY] " & _
"AND " & stateField & "=" & table & ".[5 ST];"
If Not QueryExists(queryName) Then
Set qdf = db.CreateQueryDef(queryName)
Else
Set qdf = db.QueryDefs(queryName)
End If
qdf.SQL = strSQL 'Match the SQL to the query name
Set rs = db.OpenRecordset(queryName)
cityOutputField = rs![3 city]
stateOutputField = rs![3 st]
rs.Close
Set rs = Nothing
db.QueryDefs.Delete queryName 'working to put this when query window closes
End Function
When I run I get "Run-time error '3061' Too few paramaters expected 2" In reference to the db.OpenRecordset() line at the end. The function is called from a button event with:
Code:
FindCityState table, "forms!Main!oCity", "forms!Main!oState", Me.OriginCity, Me.OriginState
and table is also a string variable