G
Guest
I have entered the following
Private Sub Command45_Click()
Dim db As Database
Dim strSQL As String
Dim Stable As String
Dim qdf As QueryDef
Set db = CurrentDb
If Forms!RecSelect!Tables = "Company" Then
Stable = "Companies"
End If
strSQL = "SELECT " & Stable & ".SwitchPhone, "
strSQL = strSQL & " FROM " & Stable
strSQL = strSQL & " WHERE (((" & Stable & "." &
Forms!RecSelect!SelectField
strSQL = strSQL & ") " & Forms!RecSelect!Operator1
If Forms!RecSelect!Operator1 = "Like" Then
strSQL = strSQL & Chr(34) & Chr(42)
strSQL = strSQL & Forms!RecSelect!Criteria1 & Chr(42) & Chr(34)
Else
strSQL = strSQL & Forms!RecSelect!Criteria1
End If
strSQL = strSQL & "))"
Me.Text46 = strSQL
db.QueryDefs.Delete ("Search")
Set qdf = db.CreateQueryDef("Search", strSQL)
End Sub
If I leave out the db.QueryDefs.Delete ("Search") part, it will only run
once and then report an error that it already exists
When I put db.QueryDefs.Delete ("Search") to try and delete the query before
recreating it, I have also tried Append .
Amiga1200
Private Sub Command45_Click()
Dim db As Database
Dim strSQL As String
Dim Stable As String
Dim qdf As QueryDef
Set db = CurrentDb
If Forms!RecSelect!Tables = "Company" Then
Stable = "Companies"
End If
strSQL = "SELECT " & Stable & ".SwitchPhone, "
strSQL = strSQL & " FROM " & Stable
strSQL = strSQL & " WHERE (((" & Stable & "." &
Forms!RecSelect!SelectField
strSQL = strSQL & ") " & Forms!RecSelect!Operator1
If Forms!RecSelect!Operator1 = "Like" Then
strSQL = strSQL & Chr(34) & Chr(42)
strSQL = strSQL & Forms!RecSelect!Criteria1 & Chr(42) & Chr(34)
Else
strSQL = strSQL & Forms!RecSelect!Criteria1
End If
strSQL = strSQL & "))"
Me.Text46 = strSQL
db.QueryDefs.Delete ("Search")
Set qdf = db.CreateQueryDef("Search", strSQL)
End Sub
If I leave out the db.QueryDefs.Delete ("Search") part, it will only run
once and then report an error that it already exists
When I put db.QueryDefs.Delete ("Search") to try and delete the query before
recreating it, I have also tried Append .
Amiga1200