|
-
Apr 14th, 2004, 03:24 AM
#1
Thread Starter
Member
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
-
Apr 14th, 2004, 04:42 AM
#2
Thread Starter
Member
ok, I can now connect to a database and run a simple update statement using:
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 I still cannot successfully return a recordSet. When I use the code below, the recordset count = -1. Can anyone see why?
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
-
Apr 14th, 2004, 08:38 AM
#3
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|