March 31st, 2004, 04:31 AM
Request Value from table..
Hi all, I dont what is command to request the value from table and display them in textbox.
This what I have (Access);
Table Name :
- MemberID, MemberName, MemberAge.
I want to display MemberName(Attribute) in txtName(textBox) where MemberID(Attribute) equal to 1234 (Key in by user in VB)
Please give me some guide how to do this.
March 31st, 2004, 06:26 AM
Hope i am not being too rude First of all JohnHACK this should be in "Code Reviw" or "General Chit Chat" not "Programming Security" I am saing this because you have posted 163 odd post and i think have been long enough to know which goes were.
Now for your Question . Command??? , You mean the SQL statement right
I have made a small program in VB i am in school right now and done it in a hurry So there is no error handling nothing and Sorry i have not added comments to the code if you do not understand any of it please feel free to ask.
I have attached the Program
It works like this You enter the MemberID into the MemberId TextBox like "1001". Then Press Enter The Correaponding records of member with that ID will be displayed in the text boxes.
Here i have added a few comments to the Code Sorry i do not have Visual Studio At home otherwise i would have edited the program itself
'Define con as new ADODB connection this is on top this is a global declaration
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Private Sub cmdClrText_Click()
'Baaa Command Button Clear to clear the All The Text Fields
txtMemberID.Text = ""
txtMemberName.Text = ""
txtMemberAge.Text = ""
Private Sub Form_Load()
Set con = New ADODB.Connection
con.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Member.mdb;Persist Security Info=False")
Set rs = New ADODB.Recordset
Private Sub txtMemberID_KeyDown(KeyCode As Integer, Shift As Integer)
On Error Resume Next
Dim s As String
'The The SQL Statement which does the trick, retrives all teh records corrosponding to the Value Stated in the "txtMemberID" Text Box
s = "Select MemberName,MemberAge from Member_info where MemberID='" & txtMemberID.Text & "'"
'Check wehther the Key that was pressed is "Enter / Return"
If KeyCode = vbKeyReturn Then
'Fetch Records into the Recordset
rs.Open (s), con, 1, 2
'Transfer records from the Recordset to the Text Boxes
txtMemberName.Text = rs(1)
txtMemberAge.Text = rs(0)
March 31st, 2004, 01:26 PM
Thanks so much SwordFish_13. I learnt something useful from you.