Hello, I'm new to this forum and only slightly newer to VB. Actually, I'm using VBA for Access. My objective is to write a little table cleanup utility that will remove values from certain records while leaving the rest of the record values intact.
I have several books, the help screens and the Northwind db to help me figure out and work out techniques.
I seem, however, to have a FUNDAMENTAL problem that books, etc. aren't helping me with: I open a standard module in one of my databases and write the following simple code that I've copied directly from Northwind, except for changing the names of the table and the field.
Public Sub LoopRecordset()
Dim db As Database, rst As Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordset("Kitsap", dbOpenTable)
Do Until rst.EOF
Debug.Print rst!Buildings
rst.MoveNext
Loop
End Sub
The problems are:
When I attempt to dimension the database and recordset variables, the drop down menu with the Dim statement does not contain a "database" line. It does include a recordset line. I gather that this problem causes my second problem.
When I attempt to run this code with MY database (neither of these problems occur in Northwind) I get the following message:
compile: error user-defined type not defined
The Dim db as database statement is highlighted in blue and the yellow highlight is on the first line.
I (think I) read that modules and procedures have some kind of context in which the Dim statements, etc. only display the objects that are applicable to that module/procedure, but I'm just not getting what the difference between this same code does in Northwind and my database.
Just, FYI, and also a little perplexing to me, is that the DoCmd.OpenTable works just fine.
Thanks for your help; I hope someday I won't be quite so behind the 8 ball!
Tim Rood
I have several books, the help screens and the Northwind db to help me figure out and work out techniques.
I seem, however, to have a FUNDAMENTAL problem that books, etc. aren't helping me with: I open a standard module in one of my databases and write the following simple code that I've copied directly from Northwind, except for changing the names of the table and the field.
Public Sub LoopRecordset()
Dim db As Database, rst As Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordset("Kitsap", dbOpenTable)
Do Until rst.EOF
Debug.Print rst!Buildings
rst.MoveNext
Loop
End Sub
The problems are:
When I attempt to dimension the database and recordset variables, the drop down menu with the Dim statement does not contain a "database" line. It does include a recordset line. I gather that this problem causes my second problem.
When I attempt to run this code with MY database (neither of these problems occur in Northwind) I get the following message:
compile: error user-defined type not defined
The Dim db as database statement is highlighted in blue and the yellow highlight is on the first line.
I (think I) read that modules and procedures have some kind of context in which the Dim statements, etc. only display the objects that are applicable to that module/procedure, but I'm just not getting what the difference between this same code does in Northwind and my database.
Just, FYI, and also a little perplexing to me, is that the DoCmd.OpenTable works just fine.
Thanks for your help; I hope someday I won't be quite so behind the 8 ball!
Tim Rood