Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    gostap is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2017
    Posts
    30

    Cascade comboboxes again... :)

    Cascade comboboxes again;




    Hi!


    For a week ago I got some help with comboboxes; grateful for that..
    But now I have a new problem/issue that I don’t know to ”attack”


    What I want my form and cascade comboboxes to do is the following:


    There are 3 comboboxes where I select ”brukare”, ”Assistent” and ”Datum”. These works excellent.

    However, in the second combobox, ”Assistent” I want to ”AfterUpdate” have the oppurtunity to print a report based on the same RecordSource as in the subform but I am not really sure how to do that. Tested some variants but It will not work. I get a error message that says ”fault 2465...can’t fiend the Field ”rptIncidSamlat” which is the name of the report(?)



    What do I wrong?



    Bg//Gostap
    Click image for larger version. 

Name:	overview.JPG 
Views:	39 
Size:	57.8 KB 
ID:	46115Click image for larger version. 

Name:	code.JPG 
Views:	37 
Size:	93.1 KB 
ID:	46116

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,543
    If the report is based on the same table/query that the form is based upon you just need the one line of code:
    DoCmd.OpenReport "rptIncidSamlat", acViewPreview, "",Enter the same criteria here as that used on the form

    The following link has an example of the criteria required for the WhereCondition argument of DoCmd.OpenReport
    https://www.codevba.com/msaccess/docmd_openreport.htm
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    gostap is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2017
    Posts
    30
    Thanks for answer, however, the main form has no recordsource. The comboboxes are in the mainform and the results is in the subform

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,543
    Quote Originally Posted by gostap View Post
    Thanks for answer, however, the main form has no recordsource. The comboboxes are in the mainform and the results is in the subform
    Can you post a copy of the db
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    I agree with Bob we need to see your database with sufficient data and instructions to
    -repeat the issue (2465) you are seeing, and
    -show us/describe to us WHAT should be happening for a correct situation.

    Please avoid jargon, and do provide specifics.

  6. #6
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Click image for larger version. 

Name:	code2.JPG 
Views:	24 
Size:	30.1 KB 
ID:	46124
    You cannot change the report record source while the report is CLOSED.



    1) I would set the report record source to "SELECT * FROM qryFiltCombo",
    2) then use the WHERE parameter of the DoCmd.OpenReport.
    DoCmd.OpenReport rptIncidSamlat, acViewPreview, , strWhere

    Code:
    Private Sub cboAssist_AfterUpdate()
        Dim strSQL As String
        Dim strSQLSF As String
        Dim strWhere As String
    
        cboDate = Null
    
        'the WHERE clause
        strWhere = " WHERE qryFiltCombo.Kund = '" & Me.cboBrukare & "' And"
        strWhere = strWhere & " qryFiltCombo.Assistent = '" & Me.cboAssist & "'"
    
        'cboDate row source
        strSQL = "SELECT DISTINCT qryFiltCombo.incDatum FROM qryFiltCombo"
        strSQL = strSQL & strWhere
        strSQL = strSQL & " ORDER BY qryFiltCombo.incDatum;"
        Debug.Print strSQL
        Me.cboDate.RowSource = strSQL
    
        'set sub form record source
        strSQLSF = "SELECT * FROM qryFiltCombo"
        strSQLSF = strSQLSF & strWhere
        Debug.Print strSQLSF
    
        Me!frmSubtblIncident.Form.RecordSource = strSQLSF
        Me.Requery
    
    
        'Preview report
        DoCmd.OpenReport "rptIncidSamlat", acViewPreview, , strWhere
    
    End Sub
    (BLUE text = Edited or added)
    Last edited by ssanfu; 09-01-2021 at 04:51 PM. Reason: forgot the quotes aqround the report name ... :(

  7. #7
    gostap is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2017
    Posts
    30
    Quote Originally Posted by Bob Fitz View Post
    Can you post a copy of the db
    Sure! by a PM?

  8. #8
    gostap is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2017
    Posts
    30
    Unfortunately iv'e got this message...
    error 2497 You must specify the Report Name argument for the action/method (Google translate)

  9. #9
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    If this is directed towards me:
    Quote Originally Posted by gostap View Post
    error 2497 You must specify the Report Name argument for the action/method (Google translate)
    Sorry, I forgot the quotes around the report name. Corrected now.

    Is there actually a report named "rptIncidSamlat"?

  10. #10
    gostap is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2017
    Posts
    30
    Yes, I actually notice the missing qoutes but still the same result...

  11. #11
    gostap is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2017
    Posts
    30
    Click image for larger version. 

Name:	syntax.JPG 
Views:	20 
Size:	23.0 KB 
ID:	46125

    Says, "
    driving error 3075.: Syntax error(operaror missing) Query expression 'Where qryFiltCombo.kund = 'Johan Persson' And qryfiltCombo.Assistant = 'Gösta Persson'"

  12. #12
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Try adding a Debug.Print line to make sure the SQL for strWhere is properly formed
    Code:
        'the WHERE clause
        strWhere = " WHERE qryFiltCombo.Kund = '" & Me.cboBrukare & "' And"
        strWhere = strWhere & " qryFiltCombo.Assistent = '" & Me.cboAssist & "'"
        Debug.Print strWhere

    It would be helpful to have a copy of the current dB (with the report and a few records) for testing...

  13. #13
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    There is no single quote after Personn?, just a double quote?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  14. #14
    gostap is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2017
    Posts
    30
    Quote Originally Posted by ssanfu View Post
    Try adding a Debug.Print line to make sure the SQL for strWhere is properly formed
    Code:
        'the WHERE clause
        strWhere = " WHERE qryFiltCombo.Kund = '" & Me.cboBrukare & "' And"
        strWhere = strWhere & " qryFiltCombo.Assistent = '" & Me.cboAssist & "'"
        Debug.Print strWhere

    It would be helpful to have a copy of the current dB (with the report and a few records) for testing...

    Here is the stripped databasestripped.zip

  15. #15
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Quote Originally Posted by Welshgasman View Post
    There is no single quote after Personn?, just a double quote?
    Methinks that is the single quote in the sql which is surrounded by 2 singles, one at the beginning, one at the end.

    Gostap, did you test this before uploading? You want it to open a report but it isn't there?
    I get a prompt for kund, which is generated by code that tries to set linkmaster and linkchild properties, but there is no bound form to link with the subform. Are you trying to build a search form and open a form or report based on the inputs? If so, why bother with the subform?

    EDIT - if you need to see the subform records, then I think you're applying the recordsource and the requery to the wrong form. In cboBrukare event, if I leave in the code to set the linked fields to 'kund' I get an error. If I rem out the problem lines, the subform doesn't show the proper records. However, if I set the subform recordsource as in

    Me.frmSubtblIncident.Form.RecordSource = strSQLSF

    then that part works. I don't see the point in assigning a recordsource to your search form and requerying it (you're using Me, which refers to the main form in this case, not the subform).
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. cascade comboboxes
    By gostap in forum Forms
    Replies: 22
    Last Post: 08-26-2021, 02:22 PM
  2. Revese a cascade comboboxes
    By epardo87 in forum Access
    Replies: 5
    Last Post: 01-20-2017, 04:01 PM
  3. Replies: 3
    Last Post: 03-31-2016, 12:16 PM
  4. cascade combo box
    By Andyjones in forum Access
    Replies: 6
    Last Post: 04-05-2012, 04:41 PM
  5. Cascade of 3 or more ComboBoxes
    By tomullus in forum Forms
    Replies: 4
    Last Post: 10-08-2011, 06:22 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