how to set value in text box based on value in combo box

  • Thread starter Thread starter ravishankar
  • Start date Start date
R

ravishankar

hi all

i want to set the value in a text box based on the value selected i
the combobox in the same form. The combobox fetches the username
from a table in the database and i want to have the correspondin
passwords in my text box from the Passwords column in the same table
 
Ravi,

Here are three ways to try:

1. Have the form based on a query that includes the user/passwords
table, which means you can include the password field in the query and
hence on the form, and then when you select the username in the
combobox, the associated password will automatically be displayed.
2. Set the Column Count property of the combobox to 2 (or whatever is
necessary to include the Password field in the Row Source of the
combobox), and then put an unbound textbox on the form, with its Control
Source set to the equivalent of...
=[NameOfCombobox].[Column](1)
3. Put an unbound textbox on the form, with its Control Source set to
the equivalent of...
=DLookup("[Password]","YourTable","[Username]='" & [YourCombobox] & "'")
 
hi steve

thanks for that. it worked fine. but the problem is i want to edit th
password that is fetched from the table. i am using the second metho
specified by you. but the system says " you cant modify the passwor
as it is bound to =[NameOfCombobox].[Column](1

please throw some light on this

rav
Steve Schapelwrote Ravi

Here are three ways to try

1. Have the form based on a query that includes the user/password
table, which means you can include the password field in the quer and
hence on the form, and then when you select the username in the
combobox, the associated password will automatically be displayed
2. Set the Column Count property of the combobox to 2 (or whateve is
necessary to include the Password field in the Row Source of the
combobox), and then put an unbound textbox on the form, with it Control
Source set to the equivalent of..
=[NameOfCombobox].[Column](1
3. Put an unbound textbox on the form, with its Control Source se to
the equivalent of..
=DLookup("[Password]","YourTable","[Username]='" [YourCombobox] & "'"

--
Steve Schapel, Microsoft Access MV


ravishankar wrote
hi all

i want to set the value in a text box based on the value selecte i
the combobox in the same form. The combobox fetches the username
from a table in the database and i want to have the correspondin
passwords in my text box from the Passwords column in the sam table
[/quote:0d689dabbf
 
Ravi,

Using the first suggested method would probably allow the password to be
edited.

Otherwise, you could take the expression out of the Control Source of
the PasswordTextbox (whatever it's called), and use the AfterUpdate
event of the combobox to run code like this...

Me.PasswordTexbox = Me.NameOfCombobox.Column(1)
 
hi stev

ya, it is working. now i have add & edit button as well as save
now when i clickon save, i have the following code. there are n
compile ar run time error still the the data does not get added o
saved(after editing ) in the table(tbl_user). i am stuck since las
three days in this this. please help

Private Sub Cmd_Save_Click(
On Error GoTo ErrorHandle


'Validation for the null values in password and confirm passwor
field
If IsNull(txtPassword.Value) Or IsNull(txtCnPwd.Value) The
MsgBox "Please enter password and then confirm password
txtPassword.SetFocu
Exit Su
End I

'Comparing the password
Dim lsStr As Strin
lsStr = StrComp(txtCnPwd, txtPassword

If lsStr = 0 The


'Save the record after "Edit
If flag = "Edit" The

' Set m_cn = New ADODB.Connectio
' Set m_rs = New ADODB.Recordse
' Set m_cn = CurrentProject.Connectio

' m_rs.Open "tbl_user", m_cn, adOpenKeyset, adLockOptimisti
' CboUserName.SetFocu
' m_rs.Fields(1) = CboUserName.Valu
' txtPassword.SetFocu
' m_rs.Fields(2) = txtPassword.Tex

'm_rs.Clos


DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord,
acMenuVer7

MsgBox "UserName successfully added

txtCnPwd.SetFocu
txtCnPwd.Text = "

txtPassword.SetFocu
txtPassword.Text = "

CboUserName.SetFocu
Dim ll_var As Lon
ll_var = Form_tbl_user.CboUserName.ListInde
ll_var =

'Save the record after "Add
End I

If flag = "Add" The

If IsNull(txtUserName) The
MsgBox "Please enter the User Name
txtUserName.SetFocu
Exit Su
End I

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord,
acMenuVer7

MsgBox "UserName successfully added

txtCnPwd.SetFocu
txtCnPwd.Text = "

txtPassword.SetFocu
txtPassword.Text = "

txtUserName.SetFocu
txtUserName.Text = "

Exit Su
End I

Els

MsgBox "The passwords do not match. Please enter again

'Clear the password and confirm password field
txtCnPwd.SetFocu
txtCnPwd.Text = "

txtPassword.SetFocu
txtPassword.Text = "

End I

Exit Su
ErrorHandler
MsgBox "Following error occurred i
Form_tbl_user:Cmd_Save_Click(): " & Err.DESCRIPTIO

End Su

Steve Schapelwrote Ravi

Using the first suggested method would probably allow the passwor to be
edited

Otherwise, you could take the expression out of the Control Sourc of
the PasswordTextbox (whatever it's called), and use the AfterUpdat
event of the combobox to run code like this..

Me.PasswordTexbox = Me.NameOfCombobox.Column(1

--
Steve Schapel, Microsoft Access MV

ravishankar wrote
hi steve

thanks for that. it worked fine. but the problem is i want to edi th
password that is fetched from the table. i am using the secon metho
specified by you. but the system says " you cant modify th passwor
as it is bound to =[NameOfCombobox].[Column](1

please throw some light on this

rav
[/quote:25d7c293b8
 
Ravi,

I will try to help, but at the moment I can't see what this is all about
or what you are trying to achive, nor can I see how this relates to your
original question. Maybe we should take a step back, and just try to
describe what this form is for, how it is supposed to work, and how it
relates to your data.
 
Back
Top