Connect to a back end in code

C

Chris K

I'm using code in a form open event to connect to back end table


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 used this before without a problem but I keep getting errors this time

I cant help wonder whether the code is OK (always was before) and I'm just
not running it early enough

Is there anyway I can run this code upon start up (not wait until the form
opens on start up)
 
D

Douglas J. Steele

Knowing the errors would definitely help people...

If the form is bound, then yes, the Load event it too late: try the Open
event instead. Your best bet, though, might be to have an unbound form as
your Startup form, and put the code in it (either Open or Load should work)
 
C

Chris K

The error varies "JHPmain (form recordsource) does not exist" - sometimes
"Disk Error"

Tried it in Form Open and still errors

I found my old database with same routine in Form Load and it connects all
five table without issue

I dont get it
 
C

Chris K

I posted the code below but here it is again:

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

RecordSource = "JHPmain"

etc
etc
 
C

Chris K

I copy/pasted the whole form/code and deleted the original and seems to be
working fine now - must got corrupted somehow
 

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