J
Jack Russell
I am trying to populate a combo box on a form in a Word template from
an Access database. I can get the whole table or the first record but
I cannot get a SQL statement to work. My code is below:
Dim myWorkspace As Workspace
Dim myDB As DAO.Database
Dim myRS As DAO.Recordset
Dim myquery As QueryDef
Dim mySQL As String
Set myWorkspace = CreateWorkspace("ODBCWorkspace", "admin", "",
dbUseODBC)
Set myDB = myWorkspace.OpenDatabase("codelist", , True) 'codelist is a
DSN
mySQL = "SELECT GreatPlainsBook.[ACCOUNT NUMBER]FROM GreatPlainsBook
WHERE GreatPlainsBook.[DIRECTORATE DETAIL]='LEISURE'"
Set myRS = myDB.OpenRecordset(mySQL, dbOpenSnapshot)
myRS.MoveFirst
MsgBox (myRS.RecordCount)
For i = 0 To myRS.RecordCount - 1
Me.ComboBox1.AddItem (myRS.Fields(0).Value)
myRS.MoveNext
Next i
End Sub
This code returns a record count of -1
Help please!
an Access database. I can get the whole table or the first record but
I cannot get a SQL statement to work. My code is below:
Dim myWorkspace As Workspace
Dim myDB As DAO.Database
Dim myRS As DAO.Recordset
Dim myquery As QueryDef
Dim mySQL As String
Set myWorkspace = CreateWorkspace("ODBCWorkspace", "admin", "",
dbUseODBC)
Set myDB = myWorkspace.OpenDatabase("codelist", , True) 'codelist is a
DSN
mySQL = "SELECT GreatPlainsBook.[ACCOUNT NUMBER]FROM GreatPlainsBook
WHERE GreatPlainsBook.[DIRECTORATE DETAIL]='LEISURE'"
Set myRS = myDB.OpenRecordset(mySQL, dbOpenSnapshot)
myRS.MoveFirst
MsgBox (myRS.RecordCount)
For i = 0 To myRS.RecordCount - 1
Me.ComboBox1.AddItem (myRS.Fields(0).Value)
myRS.MoveNext
Next i
End Sub
This code returns a record count of -1
Help please!