Results 1 to 4 of 4
  1. #1
    libraccess's Avatar
    libraccess is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Location
    Napier New Zealand
    Posts
    129

    VBA for records based on cbo Value List

    If I want to open a report and only include records based on values from a cbo based on a value list.
    Say I only have 3 records "Male", "Female", "Undecided" for example or Active, Dormant, Extinct
    If I want the report to just show Male records
    DoCmd.OpenReport "rptActive", acViewPreview, ,= -----------------------
    can somebody please tell me code that will work

    (at the moment the DB I have taken over has duplicated reports (identical) with queries for each with the condition
    =Active or <> Active but having two reports where one will do is a bit wasteful. and there are 3 instances of this.
    Thanks

  2. #2
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    "Male", "Female", "Undecided"
    Does one get to chose one's gender these days?

    The fourth argument of the OpenReport method is an optional WHERE clause (without the keyword WHERE). Looking at your example it seems you want to begin this clause with a comparison; this will not work. OK, let's try to get you going in the right direction and let's also assume the combo box is called cboReportType and that IT CONTAINS A STRING VALUE. Your DoCmd statement will then look something like this:

    DoCmd.OpenReport "rptActive", acViewPreview, , "Gender = '" & Me.cboReportType & "'"

    Use your own names as appropriate.

  3. #3
    libraccess's Avatar
    libraccess is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Location
    Napier New Zealand
    Posts
    129
    how can i consider being confused by gender when VBA is in my lap
    So while I was waiting for your answer I have on my report control menu under this reports button put a cbo which is visible false on current, btn click cbo visible then cbo after update
    Private Sub cboEmplStatus_AfterUpdate()
    If IsNull(Me.cboEmplStatus) Then
    MsgBox "Please select something first."
    Me.cboEmplStatus.SetFocus
    Else
    DoCmd.OpenReport "rptEmplList", acViewPreview, (and I've been waiting for your answer to fill this bit in)
    End If
    End Sub

    And lo it arrived and I basked in the sunshine of success
    just what i wanted thanks

  4. #4
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    DoCmd.OpenReport "rptEmplList", acViewPreview, (and I've been waiting for your answer to fill this bit in)
    You're missing a comma (after acViewPreview)!

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

Similar Threads

  1. Replies: 1
    Last Post: 02-16-2013, 11:36 AM
  2. Replies: 14
    Last Post: 12-06-2012, 11:25 AM
  3. Access 2007 - Creating New Records Based on Existing Records
    By GeorgeAugustinePhillips in forum Forms
    Replies: 9
    Last Post: 10-05-2011, 05:58 PM
  4. Replies: 12
    Last Post: 08-30-2011, 03:36 PM
  5. Replies: 3
    Last Post: 03-25-2010, 12:31 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