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

    cascade comboboxes

    Help!


    Please need some help! Hope you can understand my english!




    I have a form with 3 cascade comboboxes. Something seems to wrong in the code. If I select first one it works properly, iI do have the selected record in second box.
    After selection in second box, I can see the right records in third box, But,..in the subform list ii will not show, just viewing ”new record”


    Someone have ideas what I have done wrong?


    Gratefully//Gostap




    Private Sub cboAssist_AfterUpdate()
    Dim strSQL As String
    Dim strSQLSF As String

    cboDate = Null

    strSQL = " SELECT DISTINCT qryFiltCombo.Datum FROM qryFiltCombo "
    strSQL = strSQL & " WHERE qryFiltCombo.Kund = '" & cboBrukare & "' And "
    strSQL = strSQL & " qryFiltCombo.Assistent = '" & cboAssist & "'"
    strSQL = strSQL & " ORDER BY qryFiltCombo.Datum;"

    cboDate.RowSource = strSQL

    strSQLSF = " SELECT * FROM qryFiltCombo "
    strSQLSF = strSQLSF & " WHERE qryFiltCombo.Kund = '" & cboBrukare & "' And "
    strSQLSF = strSQLSF & " qryFiltCombo.Assistent = '" & cboAssist & "'"


    Me!frmSubtblIncident.LinkChildFields = ""
    Me!frmSubtblIncident.LinkMasterFields = ""

    Me!frmSubtblIncident.LinkChildFields = "Kund;Assistent"
    Me!frmSubtblIncident.LinkMasterFields = "Kund;Assistent"
    Me.RecordSource = strSQLSF
    Me.Requery
    End Sub

    Private Sub cboBrukare_AfterUpdate()

    Dim strSQL As String
    Dim strSQLSF As String

    cboAssist = Null
    cboDate = Null

    strSQL = "SELECT DISTINCT qryFiltCombo.Assistent FROM qryFiltCombo "
    strSQL = strSQL & " WHERE qryFiltCombo.Kund = '" & cboBrukare & "'"
    strSQL = strSQL & " ORDER BY qryFiltCombo.Assistent;"

    cboAssist.RowSource = strSQL

    strSQLSF = "SELECT * FROM qryFiltCombo "
    strSQLSF = strSQLSF & " WHERE qryFiltCombo.Kund = '" & cboBrukare & "'"

    Me!frmSubtblIncident.LinkChildFields = "Kund"
    Me!frmSubtblIncident.LinkMasterFields = "Kund"
    Me.RecordSource = strSQLSF
    Me.Requery
    End Sub

    Private Sub cboDate_AfterUpdate()
    Dim strSQLSF As String

    strSQLSF = " SELECT * FROM qryFiltCombo "
    strSQLSF = strSQLSF & " WHERE qryFiltCombo.Kund = '" & cboBrukare & "' And "
    strSQLSF = strSQLSF & " qryFiltCombo.Assistent = '" & cboAssist & "' And "
    strSQLSF = strSQLSF & " qryFiltCombo.Datum = " & cboDate

    Me!frmSubtblIncident.LinkChildFields = ""
    Me!frmSubtblIncident.LinkMasterFields = ""

    Me!frmSubtblIncident.LinkChildFields = "Kund;Assistent;Datum"
    Me!frmSubtblIncident.LinkMasterFields = "Kund;Assistent;Datum"
    Me.RecordSource = strSQLSF
    Me.Requery

    End Sub


    Click image for larger version. 

Name:	overview.JPG 
Views:	34 
Size:	57.8 KB 
ID:	46042
    Click image for larger version. 

Name:	1stselec.JPG 
Views:	37 
Size:	42.7 KB 
ID:	46043

    Click image for larger version. 

Name:	lastselect.JPG 
Views:	37 
Size:	44.5 KB 
ID:	46044

    Click image for larger version. 

Name:	designCboAndSubform.JPG 
Views:	35 
Size:	62.8 KB 
ID:	46045

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Hard to say without seeing your form. You are assigning the strSQLSF variable to the main form recordsource but I think the main form should be unbound and the variable should be used as the recordsource for the subform (and leave out the LinkChildFields\LinkMasterFields everywhere).

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Why not Debug.Print strSQLSF and see what you actually have.?
    Might need # around the date.?
    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

  4. #4
    gostap is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2017
    Posts
    30
    Quote Originally Posted by Gicu View Post
    Hard to say without seeing your form. You are assigning the strSQLSF variable to the main form recordsource but I think the main form should be unbound and the variable should be used as the recordsource for the subform (and leave out the LinkChildFields\LinkMasterFields everywhere).

    Cheers,
    Thanks for answer, I will try that...been thinking about myself..

  5. #5
    gostap is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2017
    Posts
    30
    Quote Originally Posted by Gicu View Post
    Hard to say without seeing your form. You are assigning the strSQLSF variable to the main form recordsource but I think the main form should be unbound and the variable should be used as the recordsource for the subform (and leave out the LinkChildFields\LinkMasterFields everywhere).

    Cheers,
    I tried to use unbound form...that works but however I need the Indexkey? (To commad further actions such openreport)

  6. #6
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    It looks like you have a field named "Datum" (Date)? "Date" is a reserved word in Access and a built in function and shouldn't be used for object names.


    If the Main form is unbound, you don't set the Master/Child link fields. Just change the sub form record source.

    I would like to have a copy of your dB for testing, but maybe this code will work.
    Code:
    Private Sub cboBrukare_AfterUpdate()  'user
    
        Dim strSQL As String
        Dim strSQLSF As String
    
        cboAssist = Null
        cboDate = Null
    
        ' set cboAssist combo box row source
        strSQL = "SELECT DISTINCT qryFiltCombo.Assistent FROM qryFiltCombo "
        strSQL = strSQL & " WHERE qryFiltCombo.Kund = '" & Me.cboBrukare & "'"
        strSQL = strSQL & " ORDER BY qryFiltCombo.Assistent;"
    
        Me.cboAssist.RowSource = strSQL
    
        ' set sub form record source
        strSQLSF = "SELECT * FROM qryFiltCombo "
        strSQLSF = strSQLSF & " WHERE qryFiltCombo.Kund = '" & Me.cboBrukare & "'"
        Debug.Print "cboBrukare = " & strSQLSF
        
        Me!frmSubtblIncident.RecordSource = strSQLSF
        Me.Requery
        
    End Sub
    '------------------------------------------------------------------------------------
    
    Private Sub cboAssist_AfterUpdate()   'assistant
        Dim strSQL As String
        Dim strSQLSF As String
    
        cboDate = Null
    
        ' set cboDate combo box row source
        strSQL = " SELECT DISTINCT qryFiltCombo.Datum FROM qryFiltCombo "
        strSQL = strSQL & " WHERE qryFiltCombo.Kund = '" & Me.cboBrukare & "' And "
        strSQL = strSQL & " qryFiltCombo.Assistent = '" & Me.cboAssist & "'"
        strSQL = strSQL & " ORDER BY qryFiltCombo.Datum;"
        
        Me.cboDate.RowSource = strSQL
    
        ' set sub form record source
        strSQLSF = " SELECT * FROM qryFiltCombo "
        strSQLSF = strSQLSF & " WHERE qryFiltCombo.Kund = '" & Me.cboBrukare & "' And "
        strSQLSF = strSQLSF & " qryFiltCombo.Assistent = '" & Me.cboAssist & "'"
        Debug.Print "cboAssist = " & strSQLSF
    
        Me!frmSubtblIncident.RecordSource = strSQLSF
        Me.Requery
        
    End Sub
    '------------------------------------------------------------------------------------
    
    Private Sub cboDate_AfterUpdate()    ' Date
        Dim strSQLSF As String
    
        ' set sub form record source
        strSQLSF = " SELECT * FROM qryFiltCombo "
        strSQLSF = strSQLSF & " WHERE qryFiltCombo.Kund = '" & Me.cboBrukare & "' And "
        strSQLSF = strSQLSF & " qryFiltCombo.Assistent = '" & Me.cboAssist & "' And "
        strSQLSF = strSQLSF & " qryFiltCombo.Datum = #" & Me.cboDate & "#"
        Debug.Print "cboDate = " & strSQLSF
        
        Me!frmSubtblIncident.RecordSource = strSQLSF
        Me.Requery
    
    End Sub

    Quote Originally Posted by gostap View Post
    I tried to use unbound form...that works but however I need the Indexkey? (To commad further actions such openreport)
    Can't you reference the sub form to get the PK field (IncID)?

  7. #7
    gostap is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2017
    Posts
    30
    Quote Originally Posted by ssanfu View Post
    It looks like you have a field named "Datum" (Date)? "Date" is a reserved word in Access and a built in function and shouldn't be used for object names.


    If the Main form is unbound, you don't set the Master/Child link fields. Just change the sub form record source.

    I would like to have a copy of your dB for testing, but maybe this code will work.
    Code:
    Private Sub cboBrukare_AfterUpdate()  'user
    
        Dim strSQL As String
        Dim strSQLSF As String
    
        cboAssist = Null
        cboDate = Null
    
        ' set cboAssist combo box row source
        strSQL = "SELECT DISTINCT qryFiltCombo.Assistent FROM qryFiltCombo "
        strSQL = strSQL & " WHERE qryFiltCombo.Kund = '" & Me.cboBrukare & "'"
        strSQL = strSQL & " ORDER BY qryFiltCombo.Assistent;"
    
        Me.cboAssist.RowSource = strSQL
    
        ' set sub form record source
        strSQLSF = "SELECT * FROM qryFiltCombo "
        strSQLSF = strSQLSF & " WHERE qryFiltCombo.Kund = '" & Me.cboBrukare & "'"
        Debug.Print "cboBrukare = " & strSQLSF
        
        Me!frmSubtblIncident.RecordSource = strSQLSF
        Me.Requery
        
    End Sub
    '------------------------------------------------------------------------------------
    
    Private Sub cboAssist_AfterUpdate()   'assistant
        Dim strSQL As String
        Dim strSQLSF As String
    
        cboDate = Null
    
        ' set cboDate combo box row source
        strSQL = " SELECT DISTINCT qryFiltCombo.Datum FROM qryFiltCombo "
        strSQL = strSQL & " WHERE qryFiltCombo.Kund = '" & Me.cboBrukare & "' And "
        strSQL = strSQL & " qryFiltCombo.Assistent = '" & Me.cboAssist & "'"
        strSQL = strSQL & " ORDER BY qryFiltCombo.Datum;"
        
        Me.cboDate.RowSource = strSQL
    
        ' set sub form record source
        strSQLSF = " SELECT * FROM qryFiltCombo "
        strSQLSF = strSQLSF & " WHERE qryFiltCombo.Kund = '" & Me.cboBrukare & "' And "
        strSQLSF = strSQLSF & " qryFiltCombo.Assistent = '" & Me.cboAssist & "'"
        Debug.Print "cboAssist = " & strSQLSF
    
        Me!frmSubtblIncident.RecordSource = strSQLSF
        Me.Requery
        
    End Sub
    '------------------------------------------------------------------------------------
    
    Private Sub cboDate_AfterUpdate()    ' Date
        Dim strSQLSF As String
    
        ' set sub form record source
        strSQLSF = " SELECT * FROM qryFiltCombo "
        strSQLSF = strSQLSF & " WHERE qryFiltCombo.Kund = '" & Me.cboBrukare & "' And "
        strSQLSF = strSQLSF & " qryFiltCombo.Assistent = '" & Me.cboAssist & "' And "
        strSQLSF = strSQLSF & " qryFiltCombo.Datum = #" & Me.cboDate & "#"
        Debug.Print "cboDate = " & strSQLSF
        
        Me!frmSubtblIncident.RecordSource = strSQLSF
        Me.Requery
    
    End Sub



    Can't you reference the sub form to get the PK field (IncID)?

    Hi, and thanks a lof for your help

    Unfortunately I gey this messages:

    Click image for larger version. 

Name:	code438.JPG 
Views:	27 
Size:	54.3 KB 
ID:	46054Click image for larger version. 

Name:	object doesn't support propertyORmethod.JPG 
Views:	28 
Size:	66.5 KB 
ID:	46055

    Maybe I could send you the database??

    Thansk in advance//Gostap

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Well for a start you are not spelling Brukar/Brukare consistently? :-(

    DO you have Option Explicit in all your modules.?

    What does the Debug.Print show.?

    Note, most of us do NOT speak your language, so would would need to translate the errors messages?

    This is what I have for one of my subforms, code is in the mainform.

    Code:
    Private Sub Form_Open(Cancel As Integer)
        Me.RecordSource = "qryEmails"
        Me.sfrmEmails.SourceObject = "cfrmEmails"
        Set Me.sfrmEmails.Form.Recordset = Me.Recordset
        DoCmd.RunCommand acCmdRecordsGoToLast
        DoCmd.GoToRecord acDataForm, Me.Name, acPrevious, 5 ' Needed for a continuous form as only last record shows.
        DoCmd.RunCommand acCmdRecordsGoToLast
        DoCmd.Maximize
        
    End Sub
    Notice I am using the Form.recordset of the subform control?
    Notice I had to use Set also ?
    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

  9. #9
    gostap is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2017
    Posts
    30
    Quote Originally Posted by Welshgasman View Post
    Well for a start you are not spelling Brukar/Brukare consistently? :-(

    DO you have Option Explicit in all your modules.?

    What does the Debug.Print show.?

    Note, most of us do NOT speak your language, so would would need to translate the errors messages?

    This is what I have for one of my subforms, code is in the mainform.

    Code:
    Private Sub Form_Open(Cancel As Integer)
        Me.RecordSource = "qryEmails"
        Me.sfrmEmails.SourceObject = "cfrmEmails"
        Set Me.sfrmEmails.Form.Recordset = Me.Recordset
        DoCmd.RunCommand acCmdRecordsGoToLast
        DoCmd.GoToRecord acDataForm, Me.Name, acPrevious, 5 ' Needed for a continuous form as only last record shows.
        DoCmd.RunCommand acCmdRecordsGoToLast
        DoCmd.Maximize
        
    End Sub
    Notice I am using the Form.recordset of the subform control?

    Notice I had to use Set also ?

    Sorry, Brukare are spelling the same. The attached picture is just not wide enough..

    The message say's "The object doesn't support the property or the method"

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Yes, I had a guess at 438.

    So try my method?
    The error is telling you whatever frmSubTblIncident is, it does not have a recordsource property? If that is the subform control name, then use my syntax.?

    Would help if you also copied and pasted the result of the Debug.Print for strSQLSF ?
    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

  11. #11
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Also try this please:
    Code:
    Me!frmSubtblIncident.Form.RecordSource = strSQLSF
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  12. #12
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Maybe you would post your dB for testing?

  13. #13
    gostap is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2017
    Posts
    30
    Quote Originally Posted by ssanfu View Post
    Maybe you would post your dB for testing?
    Absolutely! Will just restore it it was from beginning

  14. #14
    gostap is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2017
    Posts
    30
    Here is the database. Whar doesn't work is a cascade combobox in "huvuudmeny" in tag "rapporter och utskrifter"//Filtrerade Incidenter. When I select in the comboboxes all works fine, but in the last combox "datum", when I select a Date then the subform goes to "new record"? I can't find out what I have done wrong?

    Hmmm, seems that I cant upload the file? How do I manage that? When I attach file I cant see them??

  15. #15
    gostap is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2017
    Posts
    30
    Quote Originally Posted by ssanfu View Post
    Maybe you would post your dB for testing?

    how can I do that??

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

Similar Threads

  1. Cascade Forms
    By Perceptus in forum Forms
    Replies: 4
    Last Post: 12-14-2017, 03:01 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. Relationship Cascade help
    By murry in forum Database Design
    Replies: 6
    Last Post: 04-16-2012, 10:49 AM
  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