If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Help with SELECT Statement Please...
Hi
I'm still learning access and am trying some of the native coding. The snippet below is the code behind a command button on a form. All the database, table and field names are okay and have been checked against the source but everytime I run it I'm getting a type 13 error. Does anyone know what I'm doing wrong? Thanks in advance for any help - this is really driving me crazy as I've compared it to various statements within Access Help and still can't see anything wrong. Peter PS SELECT line is continuous but has been split by the posting system so it shouldn't have an underscore after the FROM statement. Sub Command0_Click() Dim dbsmgrs As Database Dim mgrs2 As Recordset Set dbsmgrs = OpenDatabase("TestTest.mdb") Set mgrs2 = dbsmgrs.OpenRecordset("SELECT ManagerName FROM Managers", dbReadOnly) recsfound = mgrss.RecordCount MsgBox (recsfound) |
#2
|
|||
|
|||
Help with SELECT Statement Please...
"Peter" wrote in message
Hi I'm still learning access and am trying some of the native coding. The snippet below is the code behind a command button on a form. All the database, table and field names are okay and have been checked against the source but everytime I run it I'm getting a type 13 error. Does anyone know what I'm doing wrong? Thanks in advance for any help - this is really driving me crazy as I've compared it to various statements within Access Help and still can't see anything wrong. Peter PS SELECT line is continuous but has been split by the posting system so it shouldn't have an underscore after the FROM statement. Sub Command0_Click() Dim dbsmgrs As Database Dim mgrs2 As Recordset Set dbsmgrs = OpenDatabase("TestTest.mdb") Set mgrs2 = dbsmgrs.OpenRecordset("SELECT ManagerName FROM Managers", dbReadOnly) recsfound = mgrss.RecordCount MsgBox (recsfound) The odds are that your code isn't really in error at all, but rather that you simply need to specify that the Recordset object you're declaring is a DAO recordset, not an ADODB recordset. I'm assuming you have a reference set to the DAO object library, because your would get an "undefined type" error on "Dim dbsmgrs As Database" if you didn't, but I guess you also have a reference set to the ADO library, which also defines a Recordset object. Try changing your declarations to disambiguate them, as follows: Dim dbsmgrs As DAO.Database Dim mgrs2 As DAO.Recordset -- Dirk Goldgar, MS Access MVP www.datagnostics.com (please reply to the newsgroup) |
Thread Tools | |
Display Modes | |
|
|