DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Need Help Accessing Data

  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    Need Help Accessing Data

    [Originally posted by Bryan]

    I am learning VB6, and am working on a project, and am having a devil of time sorting this out.I have an application that needs to take 9 numbers [already verified], check an [access] data-base, then if found, populate the 4 remaining text boxes with the remaining fields associated with that number.
    A User enters 9 numbers into txtInput [exists]
    Clicks Search [exists]
    The code has to open and search the database for the inputted number and to populate 4 remaining text boxes if found. As follows......
    Database is rndb.mdb
    Table is tblNumbers
    Field 1 is Number [represents the 9 numbers and is primary key]
    Field 2 is Name
    Field 3 is City
    Field 4 is State
    Field 5 is Phone

    Text boxes to populate and be disabled from the user are:

    txtBox2 [Field 2]
    txtBox3 [Field 3]
    txtBox4 [Field 4]
    txtBox5 [Field 5]

    If anyone can help me with this, I'd appreciate it.˙ I know I'm missing something, and if I can get a working example, this should open the door for me.˙ Thankyou very much in advance.
    Bryan


  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Need Help Accessing Data

    [Originally posted by naveen.a@parsectech.com]

    Hey the code can be like this !

    Declarations

    Dim cnn as adodb.connnection
    dim rsTemp as adodb.recordset
    'put this code in Form Load()

    'Opening connection
    set cnn = new adodb.connection
    cnn.open <<give ur connection string here>>
    'Opening recordset
    rsTemp.open "tblNumbers",cnn,adopendynaic,adlockoptimistic

    'Put this code on the click of search button

    if not (rsTemp.bof and rsTemp.eof) then
    ˙ ˙ 'Setting pointer to first record
    ˙ ˙ rsTemp.movefirst
    ˙ ˙ 'Finding record
    ˙ ˙ rstemp.find "Number=" & txtnumber.text
    ˙ ˙ if not rsTemp.eof then˙ ˙ 'Record Found
    ˙ ˙ ˙ ˙ 'Taking values to text boxes
    ˙ ˙ ˙ ˙ txtName=rsTemp!Name
    ˙ ˙ ˙ ˙ txtCity=rsTemp!City
    ˙ ˙ ˙ ˙ txtState=rsTemp!State
    ˙ ˙ ˙ ˙ txtPhone=rsTemp!hone
    ˙ ˙ else
    ˙ ˙ ˙ ˙ msgbox "Record not found ", vbinformation
    ˙ ˙ endif
    endif
    -----------------------------------

    I hope this should work out !
    If U want some more examples, U can find them in MSDN.

    Naveen !!!

  3. #3
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Need Help Accessing Data

    [Originally posted by naveen.a@parsectech.com]

    Hey the code can be like this !

    Declarations

    Dim cnn as adodb.connnection
    dim rsTemp as adodb.recordset
    'put this code in Form Load()

    'Opening connection
    set cnn = new adodb.connection
    cnn.open <<give ur connection string here>>
    'Opening recordset
    rsTemp.open "tblNumbers",cnn,adopendynaic,adlockoptimistic

    'Put this code on the click of search button

    if not (rsTemp.bof and rsTemp.eof) then
    ˙ ˙ 'Setting pointer to first record
    ˙ ˙ rsTemp.movefirst
    ˙ ˙ 'Finding record
    ˙ ˙ rstemp.find "Number=" & txtnumber.text
    ˙ ˙ if not rsTemp.eof then˙ ˙ 'Record Found
    ˙ ˙ ˙ ˙ 'Taking values to text boxes
    ˙ ˙ ˙ ˙ txtName=rsTemp!Name
    ˙ ˙ ˙ ˙ txtCity=rsTemp!City
    ˙ ˙ ˙ ˙ txtState=rsTemp!State
    ˙ ˙ ˙ ˙ txtPhone=rsTemp!hone
    ˙ ˙ else
    ˙ ˙ ˙ ˙ msgbox "Record not found ", vbinformation
    ˙ ˙ endif
    endif
    -----------------------------------

    I hope this should work out !
    If U want some more examples, U can find them in MSDN.

    Naveen !!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center