zimmer9
asked on
Using Access 2003, how would you set up a default value in a 2nd combobox, based on the chosen value in the first combobox of another form?
I am developing an Access 2003 application.
On Form1, I have 1 combobox titled Combo25 that has the following value for RowSource:
Select tblUserSecurity1.recordnum , tlbUserSecurity1.userid from tblUserSecurity1 order by userid. I hide the first column and display the userid in the combobox
DefaultValue [Combo25].[ItemData](0)
On Form2, I have another combo box titled Combo27.
What value would I place in the Comb27 combobox so that it will initially display the user's choice (userid) from Combo25 and where would I place the value (DefaulValue)?
Combo27 has the same RowSource as Combo25.
On Form1, I have 1 combobox titled Combo25 that has the following value for RowSource:
Select tblUserSecurity1.recordnum
DefaultValue [Combo25].[ItemData](0)
On Form2, I have another combo box titled Combo27.
What value would I place in the Comb27 combobox so that it will initially display the user's choice (userid) from Combo25 and where would I place the value (DefaulValue)?
Combo27 has the same RowSource as Combo25.
I would do something like this:
On Form2_Load:
me.combo27.defaultvalue = forms!form1!combo25 (add .column() for the non bound value)
Then you might want to do some code in the After_Update of Combo25 like so:
forms!form2!combo27.defaul tvalue = me.combo25 (add .column() for the non bound value)
There may be some caveats you need to consider like what happens if both forms aren't open (yet).
On Form2_Load:
me.combo27.defaultvalue = forms!form1!combo25 (add .column() for the non bound value)
Then you might want to do some code in the After_Update of Combo25 like so:
forms!form2!combo27.defaul
There may be some caveats you need to consider like what happens if both forms aren't open (yet).
ASKER
Form1 that I reference is actually titled frmSignIn
In the form load for Form2, I used the statement:
Me.Combo27.DefaultValue = Forms!frmSignIn!Combo25
How would I resolve the error:
Run-time error '2450':
can't find the form 'frmSignIn' referred to in a macro expression or Visual Basic code.
In the form load for Form2, I used the statement:
Me.Combo27.DefaultValue = Forms!frmSignIn!Combo25
How would I resolve the error:
Run-time error '2450':
can't find the form 'frmSignIn' referred to in a macro expression or Visual Basic code.
ASKER
How would I keep frmSignIn open in hidden mode?
I would presume you have a button captioned something like "Log In" or "Sign In" on frmSignIn. I would hide the close button and just add this line to that button (on my sample I named it cmdHideForm, but the caption is "Sign In"):
Private Sub cmdHideForm_Click()
Me.Visible = False
End Sub
Private Sub cmdHideForm_Click()
Me.Visible = False
End Sub
<<In the form load for Form2, I used the statement:
Me.Combo27.DefaultValue = Forms!frmSignIn!Combo25
>>
No reason to assign that in code, put it right in the property sheet.
<<can't find the form 'frmSignIn' referred to in a macro expression or Visual Basic code. >>
frmSignIn needs to be open.
<<ow would I keep frmSignIn open in hidden mode? >>
Do:
frmSignIn.Visible = False
at some point.
Me.Combo27.DefaultValue = Forms!frmSignIn!Combo25
>>
No reason to assign that in code, put it right in the property sheet.
<<can't find the form 'frmSignIn' referred to in a macro expression or Visual Basic code. >>
frmSignIn needs to be open.
<<ow would I keep frmSignIn open in hidden mode? >>
Do:
frmSignIn.Visible = False
at some point.
Instead of
frmSignIn.close
use
frmSignIn.visible = false
frmSignIn.close
use
frmSignIn.visible = false
Note that should be:
Forms![frmSignIn].Visible = False
or
Me.Visible = False
depending on where the code is running (the second can be used only if the code is running in frmSignin, the other would work anywhere).
Jim.
Forms![frmSignIn].Visible = False
or
Me.Visible = False
depending on where the code is running (the second can be used only if the code is running in frmSignin, the other would work anywhere).
Jim.
Jim's solution is better than mine for this scenario. Based on the initial description, I was proposing a solution which could handle combo25 changing at any time (thus the suggestion to include code in the After_Update event of combo25).
This type of scenario could also be handled through the simple use of a global variable, unless I'm mistaken. FrmSignIn wouldn't be required to stay open in that case... I'm not sure which design is technically better... the overhead of a global variable versus a hidden form that's always open I'm sure is negligible.
This type of scenario could also be handled through the simple use of a global variable, unless I'm mistaken. FrmSignIn wouldn't be required to stay open in that case... I'm not sure which design is technically better... the overhead of a global variable versus a hidden form that's always open I'm sure is negligible.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
=Forms![Form1]![Combo25]
Jim.