Results 1 to 3 of 3

Thread: Really basic Access VBA questions

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2004
    Posts
    58

    Really basic Access VBA questions

    Hi,

    I need help with some of the most basic VBA stff in the world, (haven't done any for 4 years....ish). I am trying to write some VBA in MS Access, and have three main, (initial), questions.

    1. How do you run an SQL SELECT statement in VBA Access?
    2. How do I get the results out of the returned object\recordset?
    3. How can I iterate through each record in the returned object\recordset?


    Any and all help will be very much appreciated.

    Cheers

  2. #2

    Thread Starter
    Member
    Join Date
    Feb 2004
    Posts
    58
    ok, I can now connect to a database and run a simple update statement using:

    VB Code:
    1. Dim conDatabase As ADODB.Connection
    2. Dim strSQL As String
    3.  
    4.     Set conDatabase = CurrentProject.Connection
    5.  
    6.     strSQL = "UPDATE SIMs SET Status = 'Active'"
    7.     conDatabase.Execute strSQL
    8.  
    9.     MsgBox "All status' have been set to ""Active""."
    10.  
    11.     conDatabase.Close
    12.     Set conDatabase = Nothing

    But I still cannot successfully return a recordSet. When I use the code below, the recordset count = -1. Can anyone see why?


    VB Code:
    1. Dim conDatabase As ADODB.Connection
    2. Dim strSQL As String
    3. Dim rst As Recordset
    4.  
    5.     Set conDatabase = CurrentProject.Connection
    6.  
    7.     strSQL = "SELECT * FROM SIMs"
    8.     Set rst = conDatabase.Execute(strSQL)
    9.     For i = 1 To i = rst.RecordCount
    10.         result = rst.GetString
    11.         MsgBox (result)
    12.     Next i
    13.    
    14.     conDatabase.Close
    15.     Set conDatabase = Nothing

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2004
    Posts
    58
    All sorted. Just for reference sake, please refer to

    this other post

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