Subform is not displaying records based on the criteria after clicking command button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blur
    New Member
    • Apr 2013
    • 3

    Subform is not displaying records based on the criteria after clicking command button

    Can someone help me on my issues please. I am new to access vba

    I have a form named: frmEarlyWarning System
    SubForm: frmEarlyWarning SystemSubForm
    Combox in the mainform: cboLOB

    The subform is created using an existing table but then I deleted the Record Source of it because I want to set the Record Source after I click a button and the criteria is based on the combo box. but After Clicking the button, it shows no records. Here is my code:

    Code:
    Private Sub cmdGo_Click()
    Dim strSQL As String
    
    strSQL = "SELECT [Priority],[As_Of],[LOB],[Employee_SID],[Employee_Full_Name],[Level_II_Manager_Full_Name],[Level_I_Manager_Full_Name] from [Priority] WHERE [LOB] = '" & [Forms]![frmEarlyWarningSystem]![cboLOB] & "'"
    
    With Forms![frmEarlyWarningSystem]![frmEarlyWarningSystemSubForm]
          .Form.RecordSource = strSQL
             .Requery
    End With
    
    End Sub
    I made a research already about my issue but then still no luck.

    Your help is very much appreciated!

    tia
    Last edited by Rabbit; Apr 7 '13, 05:16 AM. Reason: Please use code tags when posting code.
  • nico5038
    Recognized Expert Specialist
    • Nov 2006
    • 3080

    #2
    I would start with placing a breakpoint (click left ruler to get a dot) in the code for the strSQL.
    Then activate the window and press the button.
    The debugger will kick in and show the code.
    Next press F8 (single step in debugging) and type in the Immediate window (normally at the bottom, but you could have to activate in from the menu):
    ?strSQL
    and press ENTER.
    This will show the query text.
    Finally copy/paste the query text in a new query and run it to see the result.

    Some possible problems are a LOB field being numeric while you add ' s around it (text datatype) or leading or trailing blanks..

    Nic;o)

    Comment

    Working...