Results 1 to 7 of 7

Thread: Simple Access code queries [resolved]

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2004
    Posts
    58

    Simple Access code queries [resolved]

    Hi,

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

    1. How do you run an SQL SELECT statement from VBA Access? I can run a simple update, but my select goes pair shaped...see code below:
    2. How do I get the results out of the returned object\recordset?

    Any and all help will be very much appreciated.

    Cheers

    Simple Update that works fine
    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 this SELECT statement returns -1 in the recordset size
    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
    Last edited by mr_tango; Apr 14th, 2004 at 08:36 AM.

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