Results 1 to 3 of 3

Open a report from a drop down combo but 1 of the reports requires a subroutine

  1. #1
    geotrouvetout67 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2019
    Posts
    107

    Open a report from a drop down combo but 1 of the reports requires a subroutine


    Hi,

    I have a combo box that opens reports but one of the reports originally had a click button that runs a somewhat complex code (that I did not write myself) to build the report. I'm beginning with VBA and having trouble writing that If/else code. Side question, what is the best way to learn Access VBA coding? I'm not finding books that seem to be recent. I'm learning trough fiddling with codes but lacking bases to better understand what I'm doing and debugging.

    The original code is the quoted DoCmd.OpenReport line below and it works but what I am trying to write instead now is

    "If report name (from the drop down) = "rptSonoco", then run the subroutine SonocoReport(), else run the OpenReport command"

    Thank you

    Code:
    Private Sub cboReportsNames_AfterUpdate()'Open corresponding report from Report combo list once filtered by purchase category already
    
    
    'DoCmd.OpenReport Me.cboReportsNames, acViewReport
    
    
    IIf (Me.cboReportsNames "rptSonoco", SonocoReport, DoCmd.OpenReport Me.cboReportsNames, acViewReport)
    
    
    
    
    End Sub
    Thank you

  2. #2
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    2,050
    Code:
    If me.cboReportsName = "rptSonoco" then
        Call SonocoReport
    else
        docmd.openreport cboReporsName, acviewpreview
    endif
    It wasn't clear what you wanted to do if the dropdown wasn't "rptSonoco". I assumed you wanted to run the report in the dropdown.

  3. #3
    geotrouvetout67 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2019
    Posts
    107
    Yes that's what I needed, it works now, thank you so much.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 09-15-2017, 07:57 AM
  2. importing data requires open/close?
    By stephenaa5 in forum Programming
    Replies: 3
    Last Post: 05-20-2017, 11:22 PM
  3. Replies: 5
    Last Post: 04-14-2016, 10:11 PM
  4. Calling Access VBA subroutine from an Excel VBA subroutine
    By richard_yolland in forum Programming
    Replies: 0
    Last Post: 02-16-2011, 11:30 AM
  5. Combo box open reports
    By GUMUBIBI in forum Programming
    Replies: 5
    Last Post: 09-06-2009, 04:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Tech Forums: Microsoft Office Forums