MultiSelect List code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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 references
in the code 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 only understand VBA a little
bit from using other people's code and configuring it for my needs. 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
 
Shel said:
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 references in the code 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 only
understand VBA a little bit from using other people's code and
configuring it for my needs. 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

In all probability you've done nothing wrong, except that you don't have
a reference set to the DAO object library. In the VB Editor, click
Tools -> References..., look down the list until you find the reference
"Microsoft DAO 3.6 Object Library", and put a check mark in the box next
to it. Then click OK to close the dialog, and all will probably be well
(unless there's some other error in your code, of course).
 
Do you have a reference set for DAO?

In your module go to Tools, References and tick the box if necessary

HTH
 
Fabulous!!! Thank you very much!

Dirk Goldgar said:
In all probability you've done nothing wrong, except that you don't have
a reference set to the DAO object library. In the VB Editor, click
Tools -> References..., look down the list until you find the reference
"Microsoft DAO 3.6 Object Library", and put a check mark in the box next
to it. Then click OK to close the dialog, and all will probably be well
(unless there's some other error in your code, of course).

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Back
Top