PDA

View Full Version : MS Access, SQL and VBa



peter
2005-01-29, 01:48 PM
Hello List

Do any of you have a module that will read a specified MS Access database using a provided SQL statement?

Peter Jamtgaard

peter
2005-01-29, 05:24 PM
Nevermind, I answered my own question
Something like this

Peter Jamtgaard


Option Explicit
Public Sub Main()
RunSQL "c:/acad/lisp/aiscdatabase.mdb", "SELECT TYPE FROM Sheet1 WHERE _ AISC_MANUAL_LABEL = 'W8X10'"
End Sub
Public Function RunSQL(ByVal strDataBase, strSQL As String)
Dim DB As Database
Dim RS As RecordSet
Dim intCount As Integer
Set DB = DBEngine.OpenDatabase(strDataBase)
Set RS = DB.OpenRecordset(strSQL, dbOpenSnapshot)
If Not RS.EOF Then
For intCount = 0 To (RS.Fields.Count - 1)
MsgBox RS.Fields.Item(intCount).Name & " = " & RS(intCount)
Next intCount
End If
RS.Close
DB.Close
End Function