Hi,
I am trying to code for a query in vb that will be executed when a certain button is clicked, and the query results will open in a different continuous form...this code has worked in the past I'm not sure why it's giving me trouble now. When I click "OK" to execute the query I get a error in vb stating there is an error in the FROM line. Here is the code from my "GUI" form where the text boxes are and the "OK" button set to execute the search (based on inputs to text boxes).
Here is the code from the form where I would like the results to display "GridDisplay"
The debugger highlights "Me.RecordSource = Form_GUI.strQuery" in yellow, however I think the problem lies within the query code on the GUI form. Any help would me much appreciated, thank you!
I am trying to code for a query in vb that will be executed when a certain button is clicked, and the query results will open in a different continuous form...this code has worked in the past I'm not sure why it's giving me trouble now. When I click "OK" to execute the query I get a error in vb stating there is an error in the FROM line. Here is the code from my "GUI" form where the text boxes are and the "OK" button set to execute the search (based on inputs to text boxes).
Code:
Option Compare Database
Option Explicit
Public strQuery As String
Private Sub new_Click()
End Sub
Private Sub Text14_Click()
Me.Text14.SelStart = 0
End Sub
Private Sub clear_Click()
Me.creatorcb.Value = Null
Me.assigncb.Value = Null
Me.Text8.Value = Null
Me.Text10.Value = Null
Me.Text12.Value = Null
Me.Text16.Value = Null
Me.Text14.Value = Null
Me.Frame20.Value = Null
End Sub
Private Sub ok_Click()
'Run query
Dim argCount As Integer
If IsNull(creatorcb.Value) And IsNull(assigncb.Value) And IsNull(Frame20) And IsNull(Text10) Then
MsgBox "You Need To Select Some Values", vbCritical, "Lead Tracking"
Exit Sub
End If
strQuery = "SELECT * From Lead Where"
If Not IsNull(creatorcb.Value) Then
strQuery = strQuery & "Creator Like '" & creatorcb.Value & "'"
argCount = argCount + 1
End If
If Not IsNull(assigncb.Value) Then
If argCount > 0 Then strQuery = strQuery & " AND "
strQuery = strQuery & "AssignedTo Like '" & assigncb.Value & "'"
argCount = argCount + 1
End If
If Not IsNull(Text8.Value) Then
If argCount > 0 Then strQuery = strQuery & " AND "
strQuery = strQuery & "BorrowerFirstName Like '" & Text8.Value & "'"
argCount = argCount + 1
End If
If Not IsNull(Text10.Value) Then
If argCount > 0 Then strQuery = strQuery & " AND "
strQuery = strQuery & "BorrowerLastName Like '" & Text10.Value & "'"
argCount = argCount + 1
End If
If Not IsNull(Text12.Value) Then
If argCount > 0 Then strQuery = strQuery & " AND "
strQuery = strQuery & "Company Like '" & Text12.Value & "'"
argCount = argCount + 1
End If
If Not IsNull(Text16.Value) Then
If argCount > 0 Then strQuery = strQuery & " AND "
strQuery = strQuery & "PropertyCity Like '" & Text16.Value & "'"
argCount = argCount + 1
End If
If Not IsNull(Text14.Value) Then
If argCount > 0 Then strQuery = strQuery & " AND "
strQuery = strQuery & "State Like '" & Text14.Value & "'"
argCount = argCount + 1
End If
If Not IsNull(Frame20.Value) Then
If argCount > 0 Then strQuery = strQuery & " AND "
strQuery = strQuery & "Status = '" & Frame20.Value & "'"
argCount = argCount + 1
End If
DoCmd.OpenForm "GridDisplay", acNormal, , , acFormEdit, acWindowNormal
End Sub
Here is the code from the form where I would like the results to display "GridDisplay"
Code:
Option Compare Database
Option Explicit
Private Sub Form_Open(cancel As Integer)
'---- SQL comes from Form_GUI.strQuery ----
Me.RecordSource = Form_GUI.strQuery
End Sub
Private Sub Status_AfterUpdate()
If Me.Status = 1 Then
Me.Text22 = "Active Qualified"
ElseIf Me.Status = 2 Then
Me.Text22 = "Follow-up Qualified"
ElseIf Me.Status = 3 Then
Me.Text22 = "Rejected"
End If
End Sub
The debugger highlights "Me.RecordSource = Form_GUI.strQuery" in yellow, however I think the problem lies within the query code on the GUI form. Any help would me much appreciated, thank you!