Share via

Cascading combobox requery problem

Anonymous
2017-04-03T14:19:04+00:00

Hi guys...

I have a combobox called cboProvinces - based on data from qryProvinces that has a column ProvinceAbbreviation. The combobox displays the ProvinceAbbreviation field in the query:

SELECT Provinces.ProvinceAbreviation

FROM Provinces;

I have a combobox called cboFirstNational that lists the corporate name of each client from the FirstNational table:

SELECT FirstNational.FirstNationalID, FirstNational.CorporateName, FirstNational.Province

FROM FirstNational

WHERE (((FirstNational.Province)=[forms]![AssessmentSessionHeaderNEW]![cboProvinces]))

ORDER BY FirstNational.CorporateName;

I am trying to figure out the requery code needed to update the data in cboCorporateName when cboProvince changes.

This is the code I have tried but it is not working - I am getting a compile error Expected function or variable.  Where am I going wrong here?

Private Sub cboProvinces_AfterUpdate()

Me.cboProvinces = Null

    Me.cboProvinces.Requery

    Me.Requery

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2017-04-03T14:33:03+00:00

    Hi,

    try with

    Private Sub cboProvinces_AfterUpdate()

        cboFirstNational.requery

    End Sub

    Ciao Mimmo

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2017-04-03T16:44:12+00:00

    To protect the integrity of the data, you should also set the cboFirstNationalNational control to Null.  Otherwise, if the user edits an existing record by selecting a different province, the value of the cboFirstNationalNational control will remain unchanged.  Its value will therefore be inconsistent with the selected province.  If the control's BoundColumn is a hidden numeric key, as will usually be the case in these circumstances, the combo box will appear to be empty, disguising the inconsistency.

    You correctly did this with your original code, albeit with the wrong combo box.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2017-04-03T15:06:50+00:00

    Thanks Mimmo - it's working, still unsure of why the error was appearing but thanks to you I discovered I was requerying the wrong control.

    Thanks again!

    Was this answer helpful?

    0 comments No comments