Steve R.
Retired
- Local time
- Today, 10:05
- Joined
- Jul 5, 2006
- Messages
- 5,692
I was trying to build a combobox in a subform. The problem has been "solved", but I would still like to get some insight into what went wrong.
Code located in the Subform:
The VBA Module Code:
The code above would work, when the subform was opened by itself. But it would NOT work when the mainform was opened. I would get an error message that the subform (strFormName) could not be found.
I have solved the problem by moving the VBA code into the subform itself and modifying it appropriately. Though the problem is solved by relocating the code, I still would like to know why it didn't work and (for future reference) how it could be made to work.
Code located in the Subform:
Code:
Call BuildState(me.name, Me.D6Field1001.Name)
The VBA Module Code:
Code:
Public Sub BuildState(strFormName As String, strControlName As String)
Forms(strFormName).Controls(strControlName).Properties("RowSource") = ""
Set BuildComboBoxRS = CurrentDb.OpenRecordset("SELECT * FROM " & csStateList & " ORDER by StateAbbreviation;", dbOpenDynaset, dbSeeChanges)
BuildComboBoxRS.MoveFirst
Forms(strFormName).Controls(strControlName).Properties("RowSourceType") = "Value List"
Forms(strFormName).Controls(strControlName).Properties("ColumnHeads") = False
strItem = "0;No Selection"
Forms(strFormName).Controls(strControlName).AddItem Item:=strItem
Do Until BuildComboBoxRS.EOF
strItem = BuildComboBoxRS!StateIDnum & ";" & BuildComboBoxRS!StateAbbreviation
Forms(strFormName).Controls(strControlName).AddItem Item:=strItem
BuildComboBoxRS.MoveNext
Loop
BuildComboBoxRS.Close
Set BuildComboBoxRS = Nothing
End Sub
The code above would work, when the subform was opened by itself. But it would NOT work when the mainform was opened. I would get an error message that the subform (strFormName) could not be found.
I have solved the problem by moving the VBA code into the subform itself and modifying it appropriately. Though the problem is solved by relocating the code, I still would like to know why it didn't work and (for future reference) how it could be made to work.