Loop Loopy

G

Guest

This code kept returning the error - "COMPILE ERROR - User-defined type not
defined" while highlighting "dbs AS Database". If anyone can help, it would
be much appreciated



Private Sub btnAddRecords_Click()
On Error GoTo Err_btnAddRecords_Click

Dim dbs As Database
Dim rst As Recordset
Dim rst2 As Recordset
Dim LoopIndex As Integer
Dim LoopIndex2 As Integer

Set dbs = CurrentDb

Set rst = dbs.OpenRecordset("SELECT * FROM TrainRoleJunc WHERE [Trainer ID]
= " & [Trainer ID].Value, dbOpenDynaset, dbSeeChanges)

Set rst2 = dbs.OpenRecordset("SELECT * FROM TRS WHERE [Trainerrole ID] = " &
[Trainerrolejunc]![TrainerRole ID], dbOpenDynaset, dbSeeChanges)

For LoopIndex = 1 To 6
rst.addnew
rst![Trainer ID] = [Trainer ID].Value
rst![Role ID] = LoopIndex
rst.Update
For LoopIndex2 = 1 To 11
rst2.addnew
rst2![TrainerRole ID] = rst![TrainerRole ID]
rst2![Subject ID] = LoopIndex2
Next LoopIndex2
Next LoopIndex

Exit_btnAddRecords_Click:
Exit Sub

Err_btnAddRecords_Click:
MsgBox Err.Description
Resume Exit_btnAddRecords_Click


End Sub
 
G

gandalf

I'm not sure if ADO as a type database.
Perhaps some reference is missing.

Open a module/form in code-view
At the menu Extra there is an item References.
Check if you have none missing. There stands MISSING:
before the item.

For the future:
try to disambiguate variables

dim fld as field
could mean
dao.field
or word.field
 
D

Dan Artuso

Hi,
You need to reference the DAO library.
With any code module open, go to Tools->References
and set a reference to DAO.xxx
where xxx is the version on your machine.
 

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