Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

QUESTION OF CHANGE VALUE (VBA IN MSACCESS)

Status
Not open for further replies.

power988

Technical User
Nov 27, 2002
2
AU
Hi, this is my first post. Very happy to visit this web for getting help.

I use office2000
I create a database called db1.mdb
and have table named : customersAge
and have fields: ID, Name, Age
1 A 1
2 B 2
3 C 3
4 D 4

I would ask a quesiton about Changing a value in Age field
by VBA.


Dim MyDb As Database
Dim MyTable As Recordset

Set MyDb = DBEngine.Workspaces(0).Databases(0)
Set MyTable = MyDb.OpenRecordset("CustomersAge", DB_OPEN_TABLE)

MyTable.Index = "Age"

MyTable.MoveFirst

Do Until MyTable.EOF
If MyTable!Age = "2" Then
MyTable.EditMode
MyTable!Age = "14"
MyTable.Update
End If
Loop


The problem here is "Dim MyDb As Database"
Error message : Type undefined.

I chance Database to DAO.Database, but still not success.

Hope anyone can help me!!! Thanks a lot.
 
Have you checked you have the DAO library referenced? (In the code window go to Tools then References)

Sharon
 
Hi Power988,

VBA can't find the library holding database stuff. In your microsoft Visual Bacis Editor, select Tools, then References.

In the list, scroll down and select Microsoft DAO 3.50 Object Library (or any other version number) if you want to use DAO. I personnally always use ADO approach for which the reference to select is "MIcrodsoft ActiveX Data Object 2.1 Library" (or other version).

Hope this helps,

Nath
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top