Results 1 to 5 of 5

Thread: How do I make a record search in Access VB? Not VB6...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Posts
    230

    Question How do I make a record search in Access VB? Not VB6...

    Here is what I do for VB but how would I write this if I was puting this in a button in Access itself?



    Set CN = New ADODB.Connection
    CN.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & App.Path & "\Database\Database.mdb"
    Set SetConnection = CN
    ConnectVar = True


    strSearchFor = List1.Text

    Do while rsPriceList Not EOF

    Set rsPriceList = New ADODB.Recordset
    rsPriceList.Open "SELECT * FROM PriceList WHERE PriceID = " & strSearchFor & "", CN, , adLockOptimistic

    rsPriceList.Fields("Name").Value = NameTxt.Text


    rsPriceList.next

    loop

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Posts
    230
    I figure it is different since you are already in that database so do you need to connect to it?

    If not that will change this right?

    Set rsPriceList = New ADODB.Recordset
    rsPriceList.Open "SELECT * FROM PriceList WHERE PriceID = " & strSearchFor & "", CN, , adLockOptimistic

  3. #3
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    If your Form is assigned to a Table, you can use Me.RecordSet.MoveNext etc.

    Or,
    You can connect (similar to VB6) like:
    VB Code:
    1. Dim sql As String
    2.     Dim rs As New ADODB.Recordset
    3.  
    4. On Error GoTo Err_Handler
    5.  
    6.  
    7.   sql = "SELECT * FROM PriceList WHERE PriceID = " & strSearchFor & ""
    8.   rsPriceList.Open sql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
    9.   Do [b]Until[/b] rsPriceList.EOF    'No need to test for EOF / BOF, as Do Until will perform the same thing
    10.     rsPriceList.Fields("Name").Value = NameTxt.Text
    11.     rsPriceList.MoveNext
    12.   Loop
    13.   rs.Close
    14.   Set rs = Nothing
    15.  
    16. 'Your Error Handler Here
    Last edited by Bruce Fox; Apr 8th, 2003 at 04:49 PM.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Posts
    230
    Thanks for your help! Today and lastnight.

    I am doing a project in just access and I haven't really used code in just that before...

  5. #5
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    No probs,

    Just note that I modified my original post to better reflect your code.



    Normaly you need to test for EOF and BOF when moving a Recordset,
    However, using Do Until rsPriceList.EOF seems to do a great job



    Bruce.
    Last edited by Bruce Fox; Apr 8th, 2003 at 04:50 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width