Can a variable be used in dependent combo box criteria?

busybee

New member
Local time
Today, 22:19
Joined
Dec 26, 2006
Messages
6
I have a main form with a "master" combo box, and on this form there is a subform with a dependent combo box. When I select a value in the master combo box, the values in the dependent combo box are filtered correctly. Everything works fine, but I would like to re-use the same subform in different main forms.

In the row source property of the dependent combo box (in the subform), I have specified the name of the main form:

[Forms]![frmQuoteAdd]![CustID]

Since "Me" is not allowed in this context (guessing from the error messages I get), I have created a variable that contains the name of the main form in the subform's Form_Open event.

Dim strFormName As String
strFormName = Me.Parent.Name
MsgBox strFormName

When the main form opens, the message box displays the name of the main form correctly, so I'm assuming this variable is recognized by the subform.

My question is, can I replace the absolute name of the main form (frmQuoteAdd) with the variable "strFromName" in the criteria of the dependent combo box? I have tried all kinds of syntax variations, but to no avail.

(I have tried other more "sophisticated" approaches with public functions using "frm As Form" as an argument, etc., but in the end, the problem is always getting Access to interpret the variable in the dependent combo box criteria.)

Thank you in advance for any help, which would be greatly appreciated.
 
try using
Code:
[Forms]!Form(strFormName).[CustID]
 
Syntax problem

Thanks for your quick reply, Bob. I gave it a try, but I get an error message (which I have to translate back to English from French for you, so it may or may not sound familiar):

"The expression entered has an invalid period (.) or an invalid exclamation point (!) or parentheses ().
You have perhaps entered an invalid identifier or typed parentheses after the Null constant."

I've checked my typing at least 10 times, so hopefully I haven't made any typos.

I think I've tried quite a few combinations of :
Forms(expression)!ControlName
[Forms]![expression]!ControlName
[Forms(expression)]!ControlName
etc.

but since I don't always know what I'm doing or why I'm doing it, "miss" seems to be outnumbering "hit".

Thanks again.
 
I'll end up with 36 subforms instead of 6!

I'll give this one last try. I've continued to work on my database, but my subforms are multiplying like rabbits because I can't find a way to use a variable in my combo box row source filter criteria (see initial message). An answer to this problem or any other approach would be of great help.

My forms operate correctly, I just feel like this is very inefficient.

Heartfelt thanks to anyone who can help!

(Sorry if this is forum heresy).
 

Users who are viewing this thread

Back
Top Bottom