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:
Dim conDatabase As ADODB.Connection Dim strSQL As String Set conDatabase = CurrentProject.Connection strSQL = "UPDATE SIMs SET Status = 'Active'" conDatabase.Execute strSQL MsgBox "All status' have been set to ""Active""." conDatabase.Close Set conDatabase = Nothing
But this SELECT statement returns -1 in the recordset size
VB Code:
Dim conDatabase As ADODB.Connection Dim strSQL As String Dim rst As Recordset Set conDatabase = CurrentProject.Connection strSQL = "SELECT * FROM SIMs" Set rst = conDatabase.Execute(strSQL) For i = 1 To i = rst.RecordCount result = rst.GetString MsgBox (result) Next i conDatabase.Close Set conDatabase = Nothing




Reply With Quote