Results 1 to 3 of 3
  1. #1
    Heatshiver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2011
    Posts
    128

    Question Stumped: Query asking for info twice?

    I have been redesigning an old 1997 DB, which is actually very good.

    The Setup: There is a form with a drop-down box filled with names that come from a table. After selecting a name you click a button which provides a graph (report). The graph is created from a query that also includes the same names as the drop-down box.



    The Issue: I have added to the existing code so that when the button is clicked, it not only opens the graph, but now closes the form and views the report instead of previewing it. I did this so that I could place buttons to navigate between the reports and forms. But now I am asked to re-insert the drop-down name in order to populate the graph, which defeats the purpose of the drop-down box.

    Here is the original code:

    Code:
    On Error GoTo Err_comcostbblgraph_Click
    
        Dim stDocName As String
        Dim cboboxtxt As String
        
        stDocName = "Cost per bbl graph"
        cboboxtxt = Me.cbofieldname.Value
        
        If cboboxtxt = "" Then
            Beep
            MsgBox "Please select a field from the drop down list", vbOKOnly, "Select field"
            Exit Sub
        End If
        DoCmd.OpenReport stDocName, acPreview
    
    Exit_comcostbblgraph_Click:
        Exit Sub
    
    Err_comcostbblgraph_Click:
        MsgBox Err.Description
        Resume Exit_comcostbblgraph_Click
    Here it is with my slight additions:

    Code:
    On Error GoTo Err_comcostbblgraph_Click
    
        Dim stDocName As String
        Dim cboboxtxt As String
        Dim WellFilter As String
        
        stDocName = "Cost per bbl graph"
        cboboxtxt = Me.cbofieldname.Value
        WellFilter = "frmwellfilter"
        
        If cboboxtxt = "" Then
            Beep
            MsgBox "Please select a field from the drop down list", vbOKOnly, "Select field"
            Exit Sub
        End If
        
        DoCmd.OpenReport stDocName, acViewReport
        DoCmd.Close acForm, WellFilter
    
    Exit_comcostbblgraph_Click:
        Exit Sub
    
    Err_comcostbblgraph_Click:
        MsgBox Err.Description
        Resume Exit_comcostbblgraph_Click
    Once I change: DoCmd.OpenReport stDocName, acPreview
    To: DoCmd.OpenReport stDocName, acViewReport

    And I click the button on the form, I get this message: "Forms!frmwellfilter!cbofieldname"
    Moreorless it's re-asking for the field name from the drop-down list. If it is re-put in, there is no problem (that I can tell). If I click OK or Cancel I get a blank table.

    I know the message comes from the Criteria in the Field Name property of the query table it uses to populate the graph, but I can't figure out how to get it back to the way it was with my coding additions...

    Any help would be greatly appreciated. Thank you.

  2. #2
    chodges is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2012
    Location
    NC
    Posts
    3

    Possible option

    Do you get the message if you don't close the form? (I suspect you aren't) Is the report bound to the query? If so, one possible solution is to use the openargs value. I'm not sure how this works with graphs, but you might try it.

    'Print report passing parameters for query
    DoCmd.OpenReport stDocName, acPreview , , , , Me.cbofieldname.Value

    Then on reportopen set the report filter

    Private Sub Report_Open(Cancel As Integer)

    Me.FilterOn = True
    Me.Filter = me.OpenArgs

    End Sub

  3. #3
    Heatshiver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2011
    Posts
    128
    Thank you for the reply.

    It is bound, but what I figured out was just hiding the form was the simplest thing I could do to get it to work as I wanted (visually).

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

Similar Threads

  1. Stumped on date
    By tmcrouse in forum Queries
    Replies: 2
    Last Post: 12-29-2011, 02:45 PM
  2. Really stumped newbie here
    By alwittlich in forum Access
    Replies: 5
    Last Post: 05-18-2011, 11:55 AM
  3. Should be simple query but I'm stumped
    By hvacfixer in forum Queries
    Replies: 9
    Last Post: 10-09-2010, 10:05 PM
  4. Stumped! Counting query based on 2 different tables
    By TheWolfster in forum Queries
    Replies: 7
    Last Post: 09-10-2010, 01:10 PM
  5. Stumped on an INSERT
    By Elisa in forum Programming
    Replies: 1
    Last Post: 12-26-2009, 10:49 AM

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