Results 1 to 4 of 4
  1. #1
    Mattbro is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Mar 2012
    Posts
    95

    Button action depending on combobox value

    Hi all,


    I am wondering-I have a form 'FrmData' linked to a table-'TblData'. On this form are textboxes and comboboxes for entering various information such as name, date etc. A combobox on the form ‘ComboColour’ has a dropdown list of several options. E.g.
    ‘Reason1-Red’
    ‘Reason2-Blue’
    ‘Reason3-Green’
    This is linked to the TblDataField [Reason]. When the fields are filled, FrmData has a button ‘Command31’ which on_click, opens a report ‘RejectReport’ based on the data entered.

    Could I code for a different report, say ‘RejectReport2’ to open, if the selection in ComboColour was ‘Reason1-Red’? I am looking at an if-then-else loop, but I am not sure how to link a selection from one control to the action of another. I’ve started with:

    Code:
     
    Private Sub Command31_Click()
    Dim Reason as String
    If Reason=" Reason1-Red " then DoCmd.openReport "RejectReport2", acPreview 
    Else DoCmd.OpenReport "RejectReport", acPreview
    End If
    End Sub
    I can see that the declaration is in the wrong place, but coding is not my forte and I am unsure what to do. Any pointers?
    Thanks,
    Mattbro

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Have your If Then Else statement evaluate the combo.


    Something Like...

    Code:
    If Me.ComboBoxName.Value = "Red" Then
        DoCmd.OpenReport "RejectReport", acPreview
        
    ElseIf Me.ComboBoxName.Value = "Blue" Then
        DoCmd.OpenReport "RejectReport1", acPreview
        
    ElseIf Me.ComboBoxName.Value = "Green" Then
        DoCmd.OpenReport "RejectReport2", acPreview
        
    Else
        MsgBox "Please make a selection before opening the report"
        Me.ComboBoxName.SetFocus
        Me.ComboBoxName.Dropdown
    End If
    You could also consider a Case Select statement when there are 3 or more options.

  3. #3
    Mattbro is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Mar 2012
    Posts
    95
    Aha. That will do nicely. Thanks for the info, ItsMe!
    M

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Also note that you can do away with the Command Button, if you want, and simply place the code in the AfterUpdate event of the Combobox, itself.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Tetbox text depending on a combobox.
    By schwabe in forum Forms
    Replies: 5
    Last Post: 01-24-2012, 05:56 PM
  2. show subform depending on combobox
    By d_Rana_b in forum Programming
    Replies: 2
    Last Post: 03-15-2011, 05:09 AM
  3. Changing calculation depending on Combobox
    By GraemeG in forum Programming
    Replies: 29
    Last Post: 02-15-2011, 11:33 AM
  4. change a combobox value depending on another
    By emadaldin in forum Access
    Replies: 3
    Last Post: 01-17-2011, 01:06 PM
  5. No action button
    By dlewicki in forum Forms
    Replies: 6
    Last Post: 12-02-2009, 12:58 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
  •  
Other Forums: Microsoft Office Forums