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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DAO - Find Table in open Database

Status
Not open for further replies.

DarrenBoyer

IS-IT--Management
Mar 2, 2004
37
CA
I have found some code that helps me to create a custom Autonumber from the Access 2002 Developer Series books. However, I don't like or understand why the authors have the Counting Table in another database.

I'm concerned this issue may cause me problems down the road, plus I should learn more about my solution anyways.

Here are the code excerpts that ask for the Counting Table outside the database.

1st off they declare the other database as a constant
[blue]Const adhcAutoNumDb = "MultiuserTrial" [/blue]

My terminology may be poor but next they perform the standard DAO setup
[blue]Dim wrk As DAO.Workspace [/blue]
Dim db As DAO.Database
Dim rstAutoNum As DAO.Recordset
Dim lngNextAutoNum As Long
Dim lngW As Long
Dim lngX As Long
Dim intRetryCount As Integer

Randomize
DoCmd.Hourglass True
intRetryCount = 0

' Open a recordset on the appropriate table in the
' autonumbers database denying all reads to others
' while it is open

[blue]Set wrk = DAO.DBEngine.Workspaces(0)
Set db = wrk.OpenDatabase(adhCurrentDBPath() & adhcAutoNumDb, False)[/blue]
Set rstAutoNum = db.OpenRecordset("tblCounter", _
dbOpenTable, dbDenyRead)

adhCurrentDBPath is a procedure that 'references' the other database with my Custom Counter table. I didn't include the code because in my limited understanding of DAO I don't expect any soultion would have to reference the filepath of another database. It seems I need to change the object I'm working with from a Workspace to a recordset but all attempts have come to failure.

My Counting Table is also called tblCounter in my main database and the Counting Field is called NextAvailableCounter.

If someone could post a suggestion or sample solution I would really appreciate it.
 
Try simply this:
Set db = CurrentDB

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
What is the failure that you experience, and on which line is it failing?

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top