Command Button problem - Access 2003

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KrazyKasper
    New Member
    • Mar 2008
    • 11

    Command Button problem - Access 2003

    I created two Command buttons in a form, one to preview the entire report and one to "cancel" or exit the form. They both work. I'm trying to create a third Command button to select/filter data from the report. My code to filter the data is:

    Private Sub SelectedContrac t_Click()
    On Error GoTo Err_SelectedCon tract_Click

    strFilter = "[LeaseMasterCont ractId] = '" & Me![LeaseMasterCont ractId] & "'"
    DoCmd.OpenRepor t "OPTIMIZEIT-Audit1", acViewPreview, , strFilter

    Exit_SelectedCo ntract_Click:
    Exit Sub

    Err_SelectedCon tract_Click:
    MsgBox Err.Description
    Resume Exit_SelectedCo ntract_Click

    End Sub

    I get the error message "Cannot find the field 'LeaseMasterCon tractId' referred to in your expression." I know the field name and report name are correct. I'm not very knowledgeable about VBA so I appreciate any help you can provide.

    Krazy
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Originally posted by KrazyKasper
    I created two Command buttons in a form, one to preview the entire report and one to "cancel" or exit the form. They both work. I'm trying to create a third Command button to select/filter data from the report. My code to filter the data is:

    [CODE=VB]
    Private Sub SelectedContrac t_Click()
    On Error GoTo Err_SelectedCon tract_Click

    strFilter = "[LeaseMasterCont ractId] = '" & Me![LeaseMasterCont ractId] & "'"
    DoCmd.OpenRepor t "OPTIMIZEIT-Audit1", acViewPreview, , strFilter

    Exit_SelectedCo ntract_Click:
    Exit Sub

    Err_SelectedCon tract_Click:
    MsgBox Err.Description
    Resume Exit_SelectedCo ntract_Click

    End Sub

    [/CODE]

    I get the error message "Cannot find the field 'LeaseMasterCon tractId' referred to in your expression." I know the field name and report name are correct. I'm not very knowledgeable about VBA so I appreciate any help you can provide.

    Krazy
    Greetings, KrazyKasper!

    Have you tried having your wizard create certain buttons for you?

    Here is what I have working to exit my database:

    [CODE=VB]

    Private Sub QuitMeNow_Click ()
    On Error GoTo Err_QuitMeNow_C lick


    DoCmd.Quit

    Exit_QuitMeNow_ Click:
    Exit Sub

    Err_QuitMeNow_C lick:
    MsgBox Err.Description
    Resume Exit_QuitMeNow_ Click

    End Sub

    [/CODE]

    Nothing fancy just add code under your button named QuitMeNow
    Here is what I ahve to pull up my reports, same deal created through wizard:

    [CODE=VB]

    'Opens Open Report
    Private Sub OpenOpenReport_ Click() ' this is your button
    On Error GoTo ErrHandler
    DoCmd.OpenRepor t "OpenMeRepo rt", acPreview, acEdit
    ErrHandler:
    Exit Sub
    End Sub

    [/CODE]

    I actually have a bit of code with the report using the On No Data procedure pane that'll allow report to not load when empty, thus get to your report in design view and add the additional info so it works well with the code above:

    [CODE=VB]

    Option Compare Database


    Private Sub Report_NoData(C ancel As Integer)
    On Error GoTo ErrHandler
    ErrHandler:
    MsgBox "Sorry! There are no records to display for this report." & vbCrLf & vbCrLf & _
    "Please be sure data available in the system to continue...", vbInformation + vbOKOnly, _
    "Data Central Report Error"
    Cancel = True
    Exit Sub
    End Sub
    [/CODE]

    Hope this helps you:-)

    In a bit!

    Dököll

    Comment

    • Fiddler2
      New Member
      • Mar 2008
      • 19

      #3
      Originally posted by KrazyKasper
      I created two Command buttons in a form, one to preview the entire report and one to "cancel" or exit the form. They both work. I'm trying to create a third Command button to select/filter data from the report. My code to filter the data is:

      Private Sub SelectedContrac t_Click()
      On Error GoTo Err_SelectedCon tract_Click

      strFilter = "[LeaseMasterCont ractId] = '" & Me![LeaseMasterCont ractId] & "'"
      DoCmd.OpenRepor t "OPTIMIZEIT-Audit1", acViewPreview, , strFilter

      Exit_SelectedCo ntract_Click:
      Exit Sub

      Err_SelectedCon tract_Click:
      MsgBox Err.Description
      Resume Exit_SelectedCo ntract_Click

      End Sub

      I get the error message "Cannot find the field 'LeaseMasterCon tractId' referred to in your expression." I know the field name and report name are correct. I'm not very knowledgeable about VBA so I appreciate any help you can provide.

      Krazy
      The field name must be in the dataset behind the form and on the form itself to be "seen" in your code. Is it there? Also, perhaps an easier way to pull this off is to parameterize your report query and reference the field on your form. To open the report, you'll only need the line you have to open the report as the filter will be "built in" to the query behind the report.

      Comment

      • KrazyKasper
        New Member
        • Mar 2008
        • 11

        #4
        Got it done.
        Thanks for your help.

        Krazy (Bill) Kasper

        Comment

        Working...