![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
When I open the form normally, ie: From the database window, the combo box works correctly. The query behind the combo box references a field on the form and shows the data. For example: SELECT tblStates.State_name, tblCountries.Country_name FROM tblCountries INNER JOIN tblStates ON tblCountries.ID = tblStates.tblCountriesID WHERE (((tblCountries.Country_name)=[forms]![frmPeople]! [Nationality])) ORDER BY tblStates.State_name; But when I open an instance of the form the combo box can't find the parameter: [forms]![frmPeople]![Nationality] and it displays an input box. I suspect this is because of the nature of the instance of the form. Is there another way to write the query so that it works for when I create an instance of the form? |
#3
| |||
| |||
|
#4
| |||
| |||
|
|
Yeah I was thinking that code was a solution. I am still hoping there is a way to write a query though? |
#5
| |||
| |||
|
#6
| |||
| |||
|
|
Yeah I was thinking that code was a solution. I am still hoping there is a way to write a query though? You are creating the form instance via code. |
#7
| |||
| |||
|
|
Sure! 'put this in a module public collForms as new Collection 'put this code in a button on a form dim frm as Form set frm = new Form1 'form1 is the name of a form you have in your database. frm.visible = true collforms.add frm, cstr(frm.hwnd) set frm = nothing The above will create multiple copies (instances) of form1. |
#8
| |||
| |||
|
#9
| |||
| |||
|
|
I wrote this function, it needs error checking code of course: Public Function GetControlsValue(strCtl As String) As Variant Dim frm As Form GetControlsValue = -1 Set frm = Application.Screen.ActiveForm * * * * GetControlsValue = frm.Controls(strCtl) End Function Now I can re-write my queries: SELECT tblStates.State_name, tblCountries.Country_name FROM tblCountries INNER JOIN tblStates ON tblCountries.ID = tblStates.tblCountriesID WHERE (((tblCountries.Country_name)=cstr(GetControlsValu e ("FieldName")))) ORDER BY tblStates.State_name; |
#10
| |||
| |||
|
|
I wrote this function, it needs error checking code of course: Public Function GetControlsValue(strCtl As String) As Variant Dim frm As Form GetControlsValue = -1 Set frm = Application.Screen.ActiveForm * * * * GetControlsValue = frm.Controls(strCtl) End Function Now I can re-write my queries: SELECT tblStates.State_name, tblCountries.Country_name FROM tblCountries INNER JOIN tblStates ON tblCountries.ID = tblStates.tblCountriesID WHERE (((tblCountries.Country_name)=cstr(GetControlsValu e ("FieldName")))) ORDER BY tblStates.State_name; |
![]() |
| Thread Tools | |
| Display Modes | |
| |