Click to See Complete Forum and Search --> : Change value of textboxes
January 19th, 2000, 03:41 AM
Hi,
How do i change the value of text2.text depending on the value i type in text1.text
eg: if i type 101 in text1.text (EmployeeID) then i want Derek (EmployeeName) to come in text2.text automatically from the database and when i type another number then the value of text2.text should change too.
Thanks alot in advance,
TOTAL BEGINNER .............. ;)
valkyrie
January 19th, 2000, 04:41 AM
Hello,
This solution is in part pseudocode since I am not sure which database you are using as your backend to this application. Anyway, here it is.
private Sub Text1_Change()
Dim strSQLString as string
'Build the SQL string
If Text1.Text <> "" then
strSQLString = "SELECT EmployeeName FROM Employee WHERE EmployeeID" = CInt(Text1.Text) ' I do a conversion here, assuming that the EmployeeID is in Integer in the DB
else
strSQLString = " "
Text2.Text = ""
exit sub 'get out of here!
End If
'You execute your SQL string and get back the results and store it in a variable, eg. VarA
'Now you can set this value to the Text2
Text2.Text = VarA
End Sub
Hope this helps... this code can also be implemented in the LostFocus event of this textbox, where if the user presses the Tab key or clicks another item in the form, the textbox loses the focus.
____________________________________
The VB Bugs in my Life...
bharat
January 20th, 2000, 12:50 AM
the solution is let me write the code for u below
declarations
dim str as string
dim rs as recordset
dim db as database 'set the database connection
On text1_change()
str="SELECT name from employee where id='" <rim(rtrim((text1.text))) &"'" ' this is if the emp_id in database is a text field
if it is a number then the query is
str="SELECT name from employee where id=" <rim(rtrim((text1.text)))
set rs=db.openrecordset(str,dbopendynaset)
if rs.recordcount<>0 then
text2.text=rs!emp_name
end if
this will be the solution for ur query
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.