Scenario: I am trying to create a multi-select list box that will add records to one of my tables. I used the code created by Roger Carlson (suggested to me by one of the helpful folk here). I changed the field and table names to fit my database.
Problem: I am getting an error (see below).
Compile error:
User-defined type not defined
When I get this error the system highlights the “Dim MyDB As DAO.Database” line of the code.
Question: What have I done wrong? As far as I can tell I have this set up like the sample database created by Roger Carlson. Obviously I’ve made an error but I need help figuring out what it is. I have included below both my code and the Roger Carlson’s code that I used as a base.
Any help is greatly appreciated. Thanks in advance.
Shel
******************MY CODE***************************
Private Sub btnOK_Click()
Dim MyDB As DAO.Database
Dim rstSelectedCat As DAO.Recordset
Dim i As Integer
Set MyDB = CurrentDb()
Set rstSelectedCat = MyDB.OpenRecordset("subtblAuditedReturns", DB_OPEN_DYNASET)
For i = 0 To lstTaxReturn.ListCount - 1
If lstTaxReturn.Selected(i) Then
rstSelectedCat.AddNew
rstSelectedCat!TaxReturn = lstTaxReturn.Column(3, i)
rstSelectedCat.UpDate
lstTaxReturn.Selected(i) = False 'clears the selection
End If
Next i
End Sub
'***************Code Created by Roger Carlson *******************
Private Sub cmdOption1_Click()
Dim MyDB As DAO.Database
Dim rstSelectedCat As DAO.Recordset
Dim i As Integer
Set MyDB = CurrentDb()
Set rstSelectedCat = MyDB.OpenRecordset("tblSelectedCat", DB_OPEN_DYNASET)
For i = 0 To lstAnswerCat.ListCount - 1
If lstAnswerCat.Selected(i) Then
rstSelectedCat.AddNew
rstSelectedCat!AnswerID = lstAnswerCat.Column(0, i)
rstSelectedCat!CatName = lstAnswerCat.Column(1, i)
rstSelectedCat.Update
lstAnswerCat.Selected(i) = False 'clears the selection
End If
Next i
End Sub
Problem: I am getting an error (see below).
Compile error:
User-defined type not defined
When I get this error the system highlights the “Dim MyDB As DAO.Database” line of the code.
Question: What have I done wrong? As far as I can tell I have this set up like the sample database created by Roger Carlson. Obviously I’ve made an error but I need help figuring out what it is. I have included below both my code and the Roger Carlson’s code that I used as a base.
Any help is greatly appreciated. Thanks in advance.
Shel
******************MY CODE***************************
Private Sub btnOK_Click()
Dim MyDB As DAO.Database
Dim rstSelectedCat As DAO.Recordset
Dim i As Integer
Set MyDB = CurrentDb()
Set rstSelectedCat = MyDB.OpenRecordset("subtblAuditedReturns", DB_OPEN_DYNASET)
For i = 0 To lstTaxReturn.ListCount - 1
If lstTaxReturn.Selected(i) Then
rstSelectedCat.AddNew
rstSelectedCat!TaxReturn = lstTaxReturn.Column(3, i)
rstSelectedCat.UpDate
lstTaxReturn.Selected(i) = False 'clears the selection
End If
Next i
End Sub
'***************Code Created by Roger Carlson *******************
Private Sub cmdOption1_Click()
Dim MyDB As DAO.Database
Dim rstSelectedCat As DAO.Recordset
Dim i As Integer
Set MyDB = CurrentDb()
Set rstSelectedCat = MyDB.OpenRecordset("tblSelectedCat", DB_OPEN_DYNASET)
For i = 0 To lstAnswerCat.ListCount - 1
If lstAnswerCat.Selected(i) Then
rstSelectedCat.AddNew
rstSelectedCat!AnswerID = lstAnswerCat.Column(0, i)
rstSelectedCat!CatName = lstAnswerCat.Column(1, i)
rstSelectedCat.Update
lstAnswerCat.Selected(i) = False 'clears the selection
End If
Next i
End Sub