Results 1 to 12 of 12
  1. #1
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    COMPILER ERROR - USER DEFINED TYPE NOT DEFINED (A2K - SR1)

    Would somebody please review the following code and let me know why I am getting a Compiler Error indicating User Defined Type not Defined at Dim dbs As DAO.Database. I got the code from another post. (I also get the Compiler error if I change the statement to Dim dbs as Database. Also let me know if anything else in the Code will go wrong.

    Signed,,, User in Distress


    Private Sub Command22_Click()

    Dim ctl As ListBox
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    Dim VarItem As Variant

    ' Set ctl to the name of the Multi Select Listbox
    Set ctl = Me!SELECTWBS

    'Exit Subroutine if the User does not select anything in the listbox
    If ctl.ItemsSelected.Count = 0 Then
    MsgBox "Please select one or more WBSIDs before pressing the Get Data Button"
    Exit Sub
    End If

    ' Start process to populate table with items selected.
    ' Table - WBS LIST BOX SELECT holds data Selected in the Listbox

    ' Delete all existing items in the table
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "DELETE-TABLE_WBS_LIST_BOX_SELECT"
    DoCmd.SetWarnings True

    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordSet("select * from TABLE - WBS LIST BOX SELECT")

    'Loop through the items selected in the listbox
    For Each VarItem In ctl.ItemsSelected
    With rst
    .AddNew
    .strCriteria = ctl.ItemData(var)
    .Update
    End With

    Next VarItem

    rst.Close
    Set ctl = Nothing
    Set dbs = Nothing
    Regards,

    Gary
    (It's been a while!)

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: COMPILER ERROR - USER DEFINED TYPE NOT DEFINED (A2K - SR1)

    In the code window, click Tools/References... and check Microsoft DAO 9.0 Object Library and the problem should be resolved.
    Francois

  3. #3
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: COMPILER ERROR - USER DEFINED TYPE NOT DEFINED (A2K - SR1)

    Hi Francois,
    Minor point but I think you mean DAO 3.6.
    Regards,
    Rory

    Microsoft MVP - Excel

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: COMPILER ERROR - USER DEFINED TYPE NOT DEFINED (A2K - SR1)

    Right, I was confused <img src=/S/blush.gif border=0 alt=blush width=15 height=15> because I am also in a thread about Outlook
    Francois

  5. #5
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: COMPILER ERROR - USER DEFINED TYPE NOT DEFINED (A2K - SR1)

    Francois and Rory,

    Thanks for the info. The DAO reference corrected the first problem. However, Now I get another Compiler Error, Method or data member not found in the .strCriteria = ctl.ItemData(var) in the below statement. Any ideas.



    'Loop through the items selected in the listbox
    For Each VarItem In ctl.ItemsSelected
    With rst
    .AddNew
    .strCriteria = ctl.ItemData(var) ---- COMPILE ERROR ON THIS LINE
    .Update
    End With
    Regards,

    Gary
    (It's been a while!)

  6. #6
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: COMPILER ERROR - USER DEFINED TYPE NOT DEFINED (A2K - SR1)

    Please note that I forgot to add strCriteria in the Dim statement, however, have added it as a String and still get the Compile Error.....
    Regards,

    Gary
    (It's been a while!)

  7. #7
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: COMPILER ERROR - USER DEFINED TYPE NOT DEFINED (A2K - SR1)

    Hi,
    Try changing .strCriteria to !strCriteria - note: I'm assuming strCriteria is the name of a field in your recordset.

    [edit after rereading the original code]
    You may want to use:
    !strCriteria = varitem

    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  8. #8
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: COMPILER ERROR - USER DEFINED TYPE NOT DEFINED (A2K - SR1)

    Rory,

    Thanks for the input... we are getting closer.

    I changed the open recordset statement as shown below to eliminate another error. I left the old code in as comments for reference. The code for this portion looks as follows:


    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordSet("SELECT [TABLE - WBS LIST BOX SELECT].WBSID FROM [TABLE - WBS LIST BOX SELECT]")
    'Set rst = dbs.OpenRecordSet("Select * from TABLE - WBS LIST BOX SELECT")
    'SELECT [TABLE - WBS LIST BOX SELECT].* FROM [TABLE - WBS LIST BOX SELECT]

    'Loop through the items selected in the listbox

    For Each VarItem In ctl.ItemsSelected
    With rst
    .AddNew
    '.strCriteria = ctl.ItemData(var)
    .Update
    End With

    Next VarItem

    Note: I commented out the strCriteria statement as I will not need it. (Sorry - I am getting sloppy.)

    Here is what I want to do. I want to update Me!SELECTWBS.Column(1, VarItem) into the table but don't know how to code it. What is happening now is that the table data is deleted and the update statement is updating the table with null values. (At least the correct number of null values is being added.)

    I hope this is understandable.
    Regards,

    Gary
    (It's been a while!)

  9. #9
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: COMPILER ERROR - USER DEFINED TYPE NOT DEFINED (A2K - SR1)

    Gary,
    Try this:
    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordSet("SELECT [TABLE - WBS LIST BOX SELECT].WBSID FROM [TABLE - WBS LIST BOX SELECT]")

    For Each VarItem In ctl.ItemsSelected
    With rst
    .AddNew
    !WBSID = ctl.itemdata(varitem)
    .Update
    End With

    Next VarItem


    I've assumed that the data you're after is in the bound column of the listbox. If not, you'll need to use ctl.column(1,varitem) instead of ctl.itemdata(varitem)
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  10. #10
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: COMPILER ERROR - USER DEFINED TYPE NOT DEFINED (A2K - SR1)

    Rory,

    Thanks for your input. Your suggestions sent me in the right direction to get this to work. The code that allows a user to select data from a Multi Select Table and then populate a table with this selection is as follows. It even works correctly.

    Private Sub Command22_Click()

    Dim ctl As ListBox
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    Dim VarItem As Variant
    Dim WBSID As String, temp As String

    ' Set ctl to the name of the Multi Select Listbox
    Set ctl = Me!SELECTWBS

    'Exit Subroutine if the User does not select anything in the listbox
    If ctl.ItemsSelected.Count = 0 Then
    MsgBox "Please select one or more WBSIDs before pressing the Get Data Button"
    Exit Sub
    End If

    ' Start process to populate table with items selected.
    ' Table - WBS LIST BOX SELECT holds data Selected in the Listbox

    ' Delete all existing items in the table
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "DELETE-TABLE_WBS_LIST_BOX_SELECT"
    DoCmd.SetWarnings True

    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordSet("SELECT [TABLE - WBS LIST BOX SELECT].WBSID FROM [TABLE - WBS LIST BOX SELECT]")

    'Loop through the items selected in the listbox

    For Each VarItem In ctl.ItemsSelected
    With rst
    .AddNew
    !WBSID = ctl.Column(1, VarItem)
    .Update
    End With

    Next VarItem

    rst.Close
    Set ctl = Nothing
    Set dbs = Nothing


    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> ... and thanks for the help. I guess I should go and take that VB course one of these days....
    Regards,

    Gary
    (It's been a while!)

  11. #11
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: COMPILER ERROR - USER DEFINED TYPE NOT DEFINED (A2K - SR1)

    <hr> I guess I should go and take that VB course one of these days....<hr>
    Do that if you're going to be programming in VB. Otherwise, it won't help you a great deal in Access because of the major difference in controls, forms and reports. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
    Charlotte

  12. #12
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: COMPILER ERROR - USER DEFINED TYPE NOT DEFINED (A2K - SR1)

    Charlotte,

    Thanks for the input regarding VB. I plan to take some classes and will look at what is available for Access.
    Regards,

    Gary
    (It's been a while!)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •