Request Value from table..
Results 1 to 3 of 3

Thread: Request Value from table..

  1. #1
    Senior Member
    Join Date
    May 2003
    Posts
    217

    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 :
    - Member_info

    Attributes :
    - MemberID, MemberName, MemberAge.


    AdodcMember(recordset)

    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.

  2. #2
    AntiOnline n00b
    Join Date
    Feb 2004
    Posts
    665
    Hi

    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.

    [edit]

    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 = ""

    End Sub



    Private Sub Form_Load()
    Set con = New ADODB.Connection
    'Connection String
    con.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Member.mdb;Persist Security Info=False")
    Set rs = New ADODB.Recordset
    End Sub


    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)
    End If

    End Sub


    --Good Luck--

  3. #3
    Senior Member
    Join Date
    May 2003
    Posts
    217
    Thanks so much SwordFish_13. I learnt something useful from you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •