Anything obviously wrong with this code?

C

Chris K

I am designing a split database + I'm moving from one machine to another and
linked tables only support absolute addressing

So I wrote some code in the front end form to link the table in the back end
(one at the mo) which is always in the same directory

Private Sub Form_Load()
Dim tbl As TableDef
For Each tbl In CurrentDb.TableDefs
If (tbl.Attributes And dbSystemObject) = 0 _
Then tbl.Connect = ";DATABASE=" & CurrentProject.path &
"\JHP_be.mdb": tbl.RefreshLink
Next
..........
..........

I wrote this few years ago and it worked perfectly - I used the same code on
more recent database and it works most of the time but sometimes has trouble
connecting and I cant imagine why?

Anything obviously wrong with this code?
 
S

Stuart McCall

Chris K said:
I am designing a split database + I'm moving from one machine to another
and linked tables only support absolute addressing

So I wrote some code in the front end form to link the table in the back
end (one at the mo) which is always in the same directory

Private Sub Form_Load()
Dim tbl As TableDef
For Each tbl In CurrentDb.TableDefs
If (tbl.Attributes And dbSystemObject) = 0 _
Then tbl.Connect = ";DATABASE=" & CurrentProject.path &
"\JHP_be.mdb": tbl.RefreshLink
Next
.........
.........

I wrote this few years ago and it worked perfectly - I used the same code
on more recent database and it works most of the time but sometimes has
trouble connecting and I cant imagine why?

Anything obviously wrong with this code?

VBA sometimes gets a bit twitchy when you use single-line If...Then
statements broken over multiple lines. Try this:

Dim tbl As TableDef
For Each tbl In CurrentDb.TableDefs
If (tbl.Attributes And dbSystemObject) = 0 Then
tbl.Connect = ";DATABASE=" & CurrentProject.path & "\JHP_be.mdb"
tbl.RefreshLink
End If
Next
 
C

Chris K

Stuart McCall said:
VBA sometimes gets a bit twitchy when you use single-line If...Then
statements broken over multiple lines. Try this:

Dim tbl As TableDef
For Each tbl In CurrentDb.TableDefs
If (tbl.Attributes And dbSystemObject) = 0 Then
tbl.Connect = ";DATABASE=" & CurrentProject.path & "\JHP_be.mdb"
tbl.RefreshLink
End If
Next

Ill give that a try thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top