Cascade combobox on continuous form (1 Viewer)

Ivy

New member
Local time
Today, 22:41
Joined
Apr 25, 2024
Messages
17
Hi all,

I would like add a cascade combo box to my subfom, but it's in continuous form and I have always error about parameter.

It works on second combobox ("ValoriCarrieraIDcmb"), only if I put manually the number of ElencoCarrieraID, for example "8".

How can I filter it?

Screenshot 2024-04-27 234646.png


Thank you very much
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:41
Joined
May 21, 2018
Messages
8,555
Besides the problem that @xavier.batlle is describing you have another problem.

The Forms collection only holds references to all open forms. It does not include forms opened as subforms. This means you can never reference a subform, or control on the subform by the subform name.
Code:
Forms!NameOfFormOpenedAsSubform.NameOfControl  (Does not work)
You have to reference as follows going from the main form through the subform control to the form in the subform control
Code:
Forms!MainFormName!SubFormControlName.Form!NameOfControlOnSubForm

In your case would have to be

Code:
SELECT
 ValoriCarrieraTbl.ValoriCarrieraID,
 ValoriCarrieraTbl.ValoriCarriera,
 ValoriCarrieraTbl.ElencoCarrieraID
FROM ValoriCarrieraTbl
WHERE
 ValoriCarrieraTbl.ElencoCarrieraID =[forms]![DipendenteM]![CarrieraM].[Form]![ElencoCarrieraIDcmb]
 
  • Like
Reactions: Ivy

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:41
Joined
May 21, 2018
Messages
8,555
I personally would not use the method referenced above by @xavier.batlle. It is OK with datasheets but it is complicated and unreliable in continuous forms. You will often get flickering or fields that partially disappear depending on the cursor location.
This method always works and IMO just easier. No complicated sql strings to code code. It requires putting a textbox over top of the combobox and rerencing that field. However, see the subforms updated controlsource.

Code:
Code:
Private Sub txtValoriCarriera_KeyDown(KeyCode As Integer, Shift As Integer)
  Me.ValoriCarrieraIDcmb.SetFocus
End Sub

Private Sub ValoriCarrieraIDcmb_Enter()
  Me.ValoriCarrieraIDcmb.Requery
End Sub

Align the textbox so that it covers the combobox except for the down arrow. Send the combobox to the back so it is behind the textbox. FYI, I do get an error when selecting from the first combobox saying the field cannot hold the value, but then it does take it. That is unrelated, but could not find the cause.


cascade.jpg
 

Attachments

  • xForumCascade_MajP.accdb
    1.9 MB · Views: 27

Ivy

New member
Local time
Today, 22:41
Joined
Apr 25, 2024
Messages
17
I personally would not use the method referenced above by @xavier.batlle. It is OK with datasheets but it is complicated and unreliable in continuous forms. You will often get flickering or fields that partially disappear depending on the cursor location.
This method always works and IMO just easier. No complicated sql strings to code code. It requires putting a textbox over top of the combobox and rerencing that field. However, see the subforms updated controlsource.

Code:
Code:
Private Sub txtValoriCarriera_KeyDown(KeyCode As Integer, Shift As Integer)
  Me.ValoriCarrieraIDcmb.SetFocus
End Sub

Private Sub ValoriCarrieraIDcmb_Enter()
  Me.ValoriCarrieraIDcmb.Requery
End Sub

Align the textbox so that it covers the combobox except for the down arrow. Send the combobox to the back so it is behind the textbox. FYI, I do get an error when selecting from the first combobox saying the field cannot hold the value, but then it does take it. That is unrelated, but could not find the cause.
Thank you very much @MajP!

Yes, it seems much simpler to me and above all I would have fewer problems in the future, in case, understanding because something doesn't work in the code.

I put your code in my "real" project (with real names, data etc) and it works fine.

Only, sorry, can I ask you how you managed to avoid the error when selecting for example "Elogio" (praise) or "Varie comunicazioni (miscellaneous communications), for those values I haven't a subgroup in the second field (not all of them do).

Screenshot 2024-04-28 195424.png


I always get an error on my db, but in your example no, how did you do it?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:41
Joined
May 21, 2018
Messages
8,555
Can you translate the error message for me? I assume that Messages is some of your own code and a custom message. There is no access error message that has "OK" and "?" as choices. My guess is in your real DB that ValoriCarrieraID is a required foreign key and that is a custom message if you forget to pick one.
 
  • Like
Reactions: Ivy

Ivy

New member
Local time
Today, 22:41
Joined
Apr 25, 2024
Messages
17
Can you translate the error message for me? I assume that Messages is some of your own code and a custom message. There is no access error message that has "OK" and "?" as choices. My guess is in your real DB that ValoriCarrieraID is a required foreign key and that is a custom message if you forget to pick one.

Found the problem!!! after hours checking every little thing by comparing the two db.. it was the join property in the query of the form "CarrieraM". Now it works perfectly!!

Screenshot 2024-04-29 003912.png


(Traslation of the error message: impossible to find any record in the "TipoCarrieraValoriTbl" table containing "ValoriCarrieraID" fields corresponding to the key)

Thanks again MajP, you're great
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:41
Joined
May 21, 2018
Messages
8,555
it was the join property in the query of the form "CarrieraM". Now it works perfectly!!
That is my fault. I forgot to mention that I had to modify the forms recordsource to that query.
 
  • Like
Reactions: Ivy

Users who are viewing this thread

Top Bottom