I have a form that i want the users to be able to make a query depending on the information they enter from two different tables. THese tables have a one to one relationship. Using the Parcelno as primary key in table a, and foriegn key in table b.
I cannot get the code right to except both tables in the select statement.
This is the code on the command button to run the query.
Private Sub cmdRunQuery_Click()
Dim db As DAO.Database
Dim QD As QueryDef
Dim where As Variant
Set db = CurrentDb()
On Error Resume Next
db.QueryDefs.Delete ("Dynamic_Query"
On Error GoTo 0
where = Null
'Evaluate Criteria entered
'parcel no
If Left(Me![ParcelNo], 1) = "*" Or Right(Me![ParcelNo], 1) = "*" Then
where = where & " AND [tblInputData].[ParcelNo] like ' " + Me![ParcelNo] + "'"
Else
where = where & " AND [tblInputData].[Parcelno] = ' " + Me![ParcelNo] + "'"
End If
'lots more fields in two tables.
'Range Queries
'LotSize range
If Not IsNull(Me![LotSizeE]) Then
where = where & " AND [tblInputData].[LotSize] between " + Me![LotSize] + " AND " & Me![LotSizeE]
Else
where = where & " AND [tblInputData].[LotSize] >= " + Me![LotSize]
End If
'lots more range query from two tables
If tblInputData <> "" Then
Set QD = db.CreateQueryDef("Dynamic_Query", "SELECT * FROM " & [tblInputData] & "INNER JOIN" & [tblBldgOver] & where)
Else
Set QD = db.CreateQueryDef("Dynamic_Query", "SELECT * FROM " & tblBldgOver & " " & where)
End If
DoCmd.OpenQuery "Dynamic_Query"
End Sub
Is there ONE select statement that will work for this? SHould i be using an inner join? i am not sure how to get this to work.
thanks
raven
I cannot get the code right to except both tables in the select statement.
This is the code on the command button to run the query.
Private Sub cmdRunQuery_Click()
Dim db As DAO.Database
Dim QD As QueryDef
Dim where As Variant
Set db = CurrentDb()
On Error Resume Next
db.QueryDefs.Delete ("Dynamic_Query"
On Error GoTo 0
where = Null
'Evaluate Criteria entered
'parcel no
If Left(Me![ParcelNo], 1) = "*" Or Right(Me![ParcelNo], 1) = "*" Then
where = where & " AND [tblInputData].[ParcelNo] like ' " + Me![ParcelNo] + "'"
Else
where = where & " AND [tblInputData].[Parcelno] = ' " + Me![ParcelNo] + "'"
End If
'lots more fields in two tables.
'Range Queries
'LotSize range
If Not IsNull(Me![LotSizeE]) Then
where = where & " AND [tblInputData].[LotSize] between " + Me![LotSize] + " AND " & Me![LotSizeE]
Else
where = where & " AND [tblInputData].[LotSize] >= " + Me![LotSize]
End If
'lots more range query from two tables
If tblInputData <> "" Then
Set QD = db.CreateQueryDef("Dynamic_Query", "SELECT * FROM " & [tblInputData] & "INNER JOIN" & [tblBldgOver] & where)
Else
Set QD = db.CreateQueryDef("Dynamic_Query", "SELECT * FROM " & tblBldgOver & " " & where)
End If
DoCmd.OpenQuery "Dynamic_Query"
End Sub
Is there ONE select statement that will work for this? SHould i be using an inner join? i am not sure how to get this to work.
thanks
raven