Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2010
    Posts
    23

    If Then Statement Help

    Hey everyone,

    At the moment I have an access program that contrains a list of products. When you double click, a generic report opens up. I then wrote three seperate reports (one for each of the three different types of products) and am attempting to write code that will open up the appropriate report depending on the product type.

    Not too familiar with the visual basic language.

    Right now my code just reads

    Private Sub Combo46_DblClick(Cancel As Integer)
    If [Table]![Basic Program Info]![Products] = "Red" Then
    DoCmd.OpenReport "Reportx"
    Else If [Table]![Basic Program Info]![Products] = "Blue" Then
    DoCmd.OpenReport "Reporty"
    Else
    DoCmd.OpenReport "Reportz"
    End If
    End Sub

    Not too sure if i am on the right track or not. Any input would be greatly appreciated.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You're in the ballpark, but not on the playing field.

    Presuming the product is on the form the code is on, the test would be:

    If Me.[Products] = "Red" Then

    The open would look like:

    DoCmd.OpenReport "Reportx"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Join Date
    Aug 2010
    Posts
    23
    Thanks a lot for the quick reply. So the value im comparing is in a list box on the form. Does the Me.[Product] command still apply?

    Thanks again for the help.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    As long as it's not a multi-select listbox, yes. It would be:

    Me.ListBoxName
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Join Date
    Aug 2010
    Posts
    23
    Alright, thanks. I'm getting pretty close to having it work. As of now my code reads

    Private Sub Combo46_DblClick(Cancel As Integer)
    If Me.Combo46 = "Red" Then
    DoCmd.OpenReport "Reportx", acViewPreview
    Else If Me.Combo46 = "Blue" Then
    DoCmd.OpenReport "reporty", acViewPreview
    Else
    DoCmd.OpenReport "reportz", acViewPreview
    End If
    End Sub

    It seems like its almost working, except it always opens reportz. Do I have to somehow modify the Me.Combo46 to tell it what column in the combo box to look into to read the color?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If Me.Combo46.Column(x) = "Red" Then

    The column property is zero based, so 0 is the first column.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. IIf Statement
    By dref in forum Forms
    Replies: 2
    Last Post: 07-16-2010, 02:46 AM
  2. IIf Statement...HELP!
    By bdhFS in forum Queries
    Replies: 5
    Last Post: 05-19-2010, 07:55 AM
  3. SQL JOIN statement
    By seen in forum Access
    Replies: 10
    Last Post: 01-15-2010, 05:34 PM
  4. IIF statement
    By james1982 in forum Access
    Replies: 1
    Last Post: 07-20-2009, 09:38 AM
  5. how to use IF then statement
    By ronnie4 in forum Access
    Replies: 1
    Last Post: 03-17-2009, 11:32 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