Link to home
Create AccountLog in
Avatar of zimmer9
zimmer9Flag for United States of America

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.
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Yes, default value.   You'd have the same rowsource, bound column, etc, and then have default value as;


=Forms![Form1]![Combo25]

Jim.
Avatar of AccessGuy1763
AccessGuy1763

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.defaultvalue = 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).
Avatar of zimmer9

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.
Avatar of zimmer9

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
<<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.
Instead of

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.
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.
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer