Huibert Posted October 8, 2008 Posted October 8, 2008 I have a VBA code loaded in AutoCad. In this code I connect to a database (access) to store data from 3dpolylines in the drawing. In this process I want to check the new selected line with the first and the last entry of the database (so i can add the selected lines to the line stored in the database). For this i make a record set of the database to figure out what the size is. This wount work as is should be!! SQL = "SELECT Nr FROM Polyline" Set rsline = DB.Execute(SQL) MsgBox rsline.RecordCount rsline.MoveLast The rsline.recordCount gives a value -1 And the movelast command gives ann error. Automation error (Error 440) (It apears that only the rsline.movenext works properly. So i can write a loop with rsline.movenext until rsline.eof = true, but this database will be quite large so I don't prefer this option.) Can someone give me a clue on how i can tackle this problem Quote
fixo Posted October 8, 2008 Posted October 8, 2008 This one worked for me: Option Compare Database Option Explicit Sub test() Dim rsline As DAO.Recordset Dim Db As DAO.Database Set Db = CurrentDb Dim SQL As String SQL = "SELECT Nr FROM Polyline" Set rsline = Db.OpenRecordset(SQL) MsgBox "Number of records are: " & rsline.RecordCount rsline.MoveLast MsgBox "Polyline number is: " & rsline!Nr ' close and clean up 'rsline' and 'Db' here if you need it End Sub ~'J'~ Quote
Huibert Posted October 9, 2008 Author Posted October 9, 2008 The problem was that I used an ADO database and not a DAO now i changed that the problem is gone. Thanks for the advise Quote
fixo Posted October 9, 2008 Posted October 9, 2008 I am glad you have solved a problem Cheers ~'J'~ Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.