ADODB.Connection Failed During Script Execution

R

Robert T

Someone in this forum helped me design a script that stepped through
tblStudents and gave each student a unique Student_ID number [text field]. I
put the script behind a command button on a form and it worked perfectly.

Now one of our students designed a table with almost 800 companies. She
created a TEXT field called Company_ID and wants Access 2003 to step through
each record, assign a unique 4-digit Company_ID, and then move to the next
record, assign the next Company_ID, etc.

Unfortunately we can't get to meat of the script because the script fails at
the
Set cn = CurrentProject.AccessConnection line.

Can someone please advise why the script stops dead in it's tracks at this
line.

Thanks,
Robert

Here's the first 3 lines in the script.

Private Sub Update_ID()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim intMax As Integer
Dim strID As String

Set cn = CurrentProject.AccessConnection
Set rs = New ADODB.Recordset
intMax = DMax("studentid", "tblStudents")
 
K

kingston via AccessMonster.com

It sounds like a library is missing. Go into the VB window and select Tools-
References. Compare what's checked in the non-functional database with
what's checked in the working one. Add the missing library and it should
work.

Robert said:
Someone in this forum helped me design a script that stepped through
tblStudents and gave each student a unique Student_ID number [text field]. I
put the script behind a command button on a form and it worked perfectly.

Now one of our students designed a table with almost 800 companies. She
created a TEXT field called Company_ID and wants Access 2003 to step through
each record, assign a unique 4-digit Company_ID, and then move to the next
record, assign the next Company_ID, etc.

Unfortunately we can't get to meat of the script because the script fails at
the
Set cn = CurrentProject.AccessConnection line.

Can someone please advise why the script stops dead in it's tracks at this
line.

Thanks,
Robert

Here's the first 3 lines in the script.

Private Sub Update_ID()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim intMax As Integer
Dim strID As String

Set cn = CurrentProject.AccessConnection
Set rs = New ADODB.Recordset
intMax = DMax("studentid", "tblStudents")
 

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