Solved Form name from a combo box as variable (1 Viewer)

LjushaMisha

Registered User.
Local time
Today, 01:08
Joined
Mar 10, 2017
Messages
55
Hi to ALL.
I'm "building" a form with 3 combo boxes:
First is ValueList RowSourceType, RowSource = "Tables";"Queries";Forms"
Depending on decision from first cbo I get the names of all tables Except left(name,4) = "MSys", all queries and all forms
Depending on decision of second cbo I get names of all fields in third cbo (RowSource type = Field list) SO FAR SO GOOD
Now I'd like to make some code to put Control names (except LABELS) in third cbo IF value in first cbo is "Forms" and decission in
second cbo is made (AfterChange Event)

Here is some kind of what I'm trying to do:

Dim f As I don't know what - form, variant, string, AccessObject, ...
Dim c As Control

Debug.Print Forms!frmdbox.cboNames.Value 'Just for testing reason - IT WORKS. So I tried next line

f = Forms!frmdbox.cboNames.Value ' Doesn't work, Missing object
Debug.Print f

DoCmd.OpenForm f, acDesign 'As I can't work with AllForms collection I have to open THE FORM named in third cbo box

For Each c In Forms!s.Controls
' If I could came here I think I would be capable to write code to make Value list from control names and
' change rowsourceType and RowSource
'c = ""
' c = c + chr(34) + c.name + chr(34) + ";" or something like that

Next

End Sub

----> In short terms, I'd like tu use value from combo box in For Each ... Next statementu

ANY HELP, PLEEEEEESE
 

LjushaMisha

Registered User.
Local time
Today, 01:08
Joined
Mar 10, 2017
Messages
55
You have propably noticed typing mistake:
WRONG: For Each c In Forms!s.Controls
CORRECT: For Each c In Forms!f.Controls
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:08
Joined
Oct 29, 2018
Messages
21,476
Hi.

1. You could use a loop but have to check:
a. the control type whether to include or not the control in your list, or
b. use the Tag property to pre-identify which controls to include in the combo, or
2. Use a list of controls per form to list stored in a table
 

LjushaMisha

Registered User.
Local time
Today, 01:08
Joined
Mar 10, 2017
Messages
55
Hi.
Ad1. I think making a loop will not be a problem (hope).
Ad2. The real problem for me is: FOR EACH Control IN Forms!ValueOfTheComboBox2.Controls
Let's say the value in second combo box is selected name of the form frmMyForm
I don't know how to:
put the value of second combo box.value
 

LjushaMisha

Registered User.
Local time
Today, 01:08
Joined
Mar 10, 2017
Messages
55
... continue

I don't know how to:
1. Open form with DoCmd.Openform ValueOfTheComboBox2 , acDesign
2. make loop with Forms!ValueOfTheComboBox2.Controls
Any suggestion???
 

LjushaMisha

Registered User.
Local time
Today, 01:08
Joined
Mar 10, 2017
Messages
55
Dim Forma As String
Dim Kontrola As Control
Dim ImeKontrole As String

ImeKontrole = ""
Forma = ""
Forma = Forma + Forms!frmDBox!cboImena.Value

DoCmd.OpenForm Forma, acDesign

For Each Kontrola In Forms(Forma).Controls
If Left(Kontrola.Name, 5) <> "Label" Then
ImeKontrole = ImeKontrole + Chr(34) + Kontrola.Name + Chr(34) + ";"
End If
Next

Me.cboFieldiKontrole.RowSourceType = "Value list"
Me.cboFieldiKontrole.RowSource = ImeKontrole
Me.cboFieldiKontrole.Requery
DoCmd.Close acForm, Forma, acSaveNo
 

Users who are viewing this thread

Top Bottom