SQL in VBA

G

Guest

Beneath you will find a piece of VBA-coding from an Access97 database, which
has always been working correctly. When I make a copy of this piece of coding
into a new database (Access97), the code doesn't work anymore (no records
found). Apparantly, MySet isn't recognized anymore ("MySet = nothing"). Can
anybody help me ?

Sub Convocatie()

On Error Resume Next
Dim I As Integer
Dim MySQL As String
Dim MyDB As Database
Dim MySet As Recordset

Set MyDB = DBEngine.Workspaces(0).Databases(0)

MySQL = "SELECT DISTINCT Soort FROM Dossiers WHERE Rnummer = '7654'"

Set MySet = MyDB.OpenRecordset(MySQL)

MySet.MoveLast
MySet.MoveFirst

I = MySet.RecordCount

MsgBox I

End Sub
 
D

Douglas J. Steele

There's nothing obviously wrong with that code.

Does it compile correctly, or are you having a problem there as well? You
might change the On Error Resume Next to actually trap any error that may be
occurring, to help figure this one out.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top