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

I should know this, but.......

Status
Not open for further replies.

PerryG

Programmer
Joined
Aug 15, 2000
Messages
75
Location
US
Why doesn't this bit of code work (Access97)?

If db.Containers("Tables").Documents(intI).Name = "AFN*" Then
strFullName = db.Containers("Tables").Documents(intI).Name
End If

The variable keeps coming up empty.

Any help appreciated.....time is short and the water is rising!

Thanks.
 
I'm not familiar with that object model but logically your test is bad ...

If db.Containers("Tables").Documents(intI).Name = "AFN*" Then

The asterisk (*) is a wild card for only the like operator...

I'm guessing you mean something like

If INSTR(1,db.Containers("Tables").Documents(intI).Name, "AFN*") = 1 Then


Personally I'd use something like...

Dim db as database
dim tbls as tabledefs
dim tbl as tabledef

set db = currentdb
set tbls = db.tabledefs

For Each tbl in tbls
If INSTR(1,tbl.Name, "AFN*") = 1 Then
strFullName = tbl.name
Exit For
End If
Next
 
I think what you need here is "LIKE", not "=".
I'm not familiar with the object model you're using,
either (It may be fine, I've just never used the
Containers or Documents collections.)
Here's some code I believe will work.

Dim db As DAO.Database
Dim tbl As DAO.TableDef

Dim strFullName as String

Set db = CurrentDb
For Each tbl In db.TableDefs
If tbl.Name Like "AFN*" Then
strFullName = tbl.Name
Exit For 'exit once we've found it
End If
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top