Update Text Box on different form from Combo Box

  • Thread starter Thread starter Joel
  • Start date Start date
J

Joel

I have a logon form (frmlogon) that validates the user and their
password. The user selection is handled by a combo box (cboemployee).
Once the account has been validated, the form is closed and a new one
is opened (frmcard). One of the text fields is for the user
(username). I am trying to find out how to pass the combo selection
from the previous form to the text field in the new form???? Any help
in this would be greatly appreciated since I have been working on this
for a few hours without any great success.
 
Validate user input in frmLogon and if valid open frmCard, but don't close
frmLogon

In frmCard:

Private Sub Form_Load()
....
Me.Username = Forms![frmLogon]![cboemployee]
DoCmd.close acForm, "frmLogon"
...
End Sub
 
The OpenArgs is the better approach. Then to use it in frimtimcard, put some
code in the Open event:

If Not IsNull(Me.OpenArgs) Then
Me.txtEmpName = Me.OpenArgs
End If
 
I appreciate your quick reply, however when I created the code as you
stated this is the error I got. Error 451 - Property let procedure not
defined and property get procedure did not return an object. I had
changed this statement - Me.Username = Forms![frmLogon]![cboemployee]
to this Me.Username = Forms![frmLogon]![cboemployee] (1) because the
answer that came back was the employee id and not the name so I thought
(1) should be the correct column and got the error message.
 
Me.Username = Forms![frmLogon]![cboemployee].columg(1)
Note, combo columns start numbering from 0
 
If you go with the Form_Load approach you can pass the Name using:

With Forms![frmLogon]![cboemployee]
Me.Username = .Column(1, .ListIndex) '.ListIndex-1 if you have column
headers.
End With
The OpenArgs is the better approach. Then to use it in frimtimcard, put some
code in the Open event:

If Not IsNull(Me.OpenArgs) Then
Me.txtEmpName = Me.OpenArgs
End If
I have a logon form (frmlogon) that validates the user and their
password. The user selection is handled by a combo box (cboemployee).
[quoted text clipped - 4 lines]
in this would be greatly appreciated since I have been working on this
for a few hours without any great success.
 
What is your problem with OpenArgs?
Also, you don't need the ListIndex at all
..Column(1) returns the current row in the combo
And, although the With ... End With construct is very useful, I would not
use it for just one property. Makes the code too verbose.

IanOxon via AccessMonster.com said:
If you go with the Form_Load approach you can pass the Name using:

With Forms![frmLogon]![cboemployee]
Me.Username = .Column(1, .ListIndex) '.ListIndex-1 if you have column
headers.
End With
The OpenArgs is the better approach. Then to use it in frimtimcard, put some
code in the Open event:

If Not IsNull(Me.OpenArgs) Then
Me.txtEmpName = Me.OpenArgs
End If
I have a logon form (frmlogon) that validates the user and their
password. The user selection is handled by a combo box (cboemployee).
[quoted text clipped - 4 lines]
in this would be greatly appreciated since I have been working on this
for a few hours without any great success.
 
'Tis only an alternative approach Klatu, and since I posted a solution, it'd
be nice to answer any questions about that. The .ListIndex approach was
originally lifted from an MSDN example...
What is your problem with OpenArgs?
Also, you don't need the ListIndex at all
.Column(1) returns the current row in the combo
And, although the With ... End With construct is very useful, I would not
use it for just one property. Makes the code too verbose.
If you go with the Form_Load approach you can pass the Name using:
[quoted text clipped - 15 lines]
 
Klatuu, I appreciate your help but I am not really up on OpenArgs? I am
basically self taught and getting more proficient everyday. I am open to all
suggestions as each seems to teach me something I didn't know before. So if
you want to get more indepth with your suggestion then I can learn from you
also. Thanks always....
What is your problem with OpenArgs?
Also, you don't need the ListIndex at all
.Column(1) returns the current row in the combo
And, although the With ... End With construct is very useful, I would not
use it for just one property. Makes the code too verbose.
If you go with the Form_Load approach you can pass the Name using:
[quoted text clipped - 15 lines]
 
The OpenArgs is an argument of the OpenForm method. If you want to pass
information to a form you are opening, then you create a string variable with
the information you want to pass. You then use that variable in the OpenForm.

So to pass the user name this way:

DoCmd.OpenForm "frmTimeCard",,,,Me.cboemployee.column(1)


Then, in the Open event of the form, you check to see if anything has been
passed and act on it.

If Not IsNull(Me.OpenArgs) Then
Me.txtEmpName = Me.OpenArgs
End If



Joel said:
Klatuu, I appreciate your help but I am not really up on OpenArgs? I am
basically self taught and getting more proficient everyday. I am open to all
suggestions as each seems to teach me something I didn't know before. So if
you want to get more indepth with your suggestion then I can learn from you
also. Thanks always....
What is your problem with OpenArgs?
Also, you don't need the ListIndex at all
.Column(1) returns the current row in the combo
And, although the With ... End With construct is very useful, I would not
use it for just one property. Makes the code too verbose.
If you go with the Form_Load approach you can pass the Name using:
[quoted text clipped - 15 lines]
in this would be greatly appreciated since I have been working on this
for a few hours without any great success.
 
I understand.

IanOxon via AccessMonster.com said:
'Tis only an alternative approach Klatu, and since I posted a solution, it'd
be nice to answer any questions about that. The .ListIndex approach was
originally lifted from an MSDN example...
What is your problem with OpenArgs?
Also, you don't need the ListIndex at all
.Column(1) returns the current row in the combo
And, although the With ... End With construct is very useful, I would not
use it for just one property. Makes the code too verbose.
If you go with the Form_Load approach you can pass the Name using:
[quoted text clipped - 15 lines]
in this would be greatly appreciated since I have been working on this
for a few hours without any great success.
 
Back
Top