If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > User-Defined Error...Need Help!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-02-11, 16:36
ctown ctown is offline
Registered User
 
Join Date: Jul 2011
Location: Chicago
Posts: 37
Question User-Defined Error...Need Help!

When switching from Design View to Normal (Form) View I get an error message...

"The expression On Click you entered as the event property setting produced the following error: User-defined Type not defined."

Here's the VBA I used from another site in trying to set up moving items between listboxes. Any idea why I'm getting this error. The link where the code can be found is...

MS Office Gurus | Access 2007 move items between listboxes, filter listbox and clear listbox Items
Reply With Quote
  #2 (permalink)  
Old 08-02-11, 16:57
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 3,446
Can you please post the code you use in the database and if possible, indicate the line that causes the error. Seeing the code on the site you mention, the first thing that comes to my mind is that your database needs a reference to the ADODB library.
__________________
Have a nice day!
Reply With Quote
  #3 (permalink)  
Old 08-02-11, 17:03
ctown ctown is offline
Registered User
 
Join Date: Jul 2011
Location: Chicago
Posts: 37
Heres the code I used in my DB

Option Compare Database
Option Explicit

'************************************************* ************************************************** ******************
'CONSTANTS
Private Const mstr_MsgBoxTitle As String = "Meu projeto Access 2007"
Private Const mstr_MsgNoItemToMove As String = "Não há item para mover ou item não foi selecionado..."
Private Const mstr_Yes As String = "Yes"
Private Const mstr_No As String = "No"
Private Const mstr_Filtered As String = "Filtered"

'************************************************* ************************************************** ******************
'STRINGS
Private mstr_SQLInstruction As String

'************************************************* ************************************************** ******************
'OBJECTS
Private mobj_ADODBRecordset As ADODB.Recordset

Sub ExecuteCommand(ByVal strExecuteSQL, ByVal strShowYesNoFilter As String)

Set mobj_ADODBRecordset = New ADODB.Recordset

With mobj_ADODBRecordset
.Open strExecuteSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
If Not .BOF Then .MoveFirst

Do While Not .EOF
.Fields("ShowYesNoFilter").Value = strShowYesNoFilter
.Update
.MoveNext
Loop
End With

Me.ListYesItems.Requery
Me.ListNoItems.Requery

mstr_SQLInstruction = ""
Set mobj_ADODBRecordset = Nothing


End Sub


Private Sub cmdAddAll_Click()
mstr_SQLInstruction = "SELECT Tbl_Skills.KeyID, Tbl_Skills.Skills, Tbl_Skills.ShowYesNoFilter, "
mstr_SQLInstruction = mstr_SQLInstruction & "Tbl_Skills.ShowYesNoFilter FROM Tbl_Skills "
mstr_SQLInstruction = mstr_SQLInstruction & "WHERE (((Tbl_Skills.ShowYesNoFilter)='" & mstr_Yes & "'));"

ExecuteCommand mstr_SQLInstruction, "No"

End Sub

Private Sub cmdAddOne_Click()
Dim strSelectedItem As String
Dim lngSelectedItemIndex As Long

On Error Resume Next
If Me.ListYesItems.ListIndex = -1 Then
MsgBox mstr_MsgNoItemToMove, vbInformation, mstr_MsgBoxTitle
Exit Sub
End If

lngSelectedItemIndex = Me.ListYesItems.ListIndex
strSelectedItem = Me.ListYesItems.ItemData(lngSelectedItemIndex)

If Len(Me.ListYesItems.ItemData(lngSelectedItemIndex) ) < 1 Then
MsgBox mstr_MsgNoItemToMove, vbInformation, mstr_MsgBoxTitle
Exit Sub
End If


mstr_SQLInstruction = "SELECT Tbl_Skills.KeyID, Tbl_Skills.Skills, Tbl_Skills.ShowYesNoFilter, "
mstr_SQLInstruction = mstr_SQLInstruction & "Tbl_Skills.ShowYesNoFilter FROM Tbl_Skills "
mstr_SQLInstruction = mstr_SQLInstruction & "WHERE (((Tbl_Skills.Skills)='" & strSelectedItem & "'));"

ExecuteCommand mstr_SQLInstruction, mstr_No

End Sub

Private Sub cmdRemoveAll_Click()
mstr_SQLInstruction = "SELECT Tbl_Skills.KeyID, Tbl_Skills.Skills, Tbl_Skills.ShowYesNoFilter, "
mstr_SQLInstruction = mstr_SQLInstruction & "Tbl_Skills.ShowYesNoFilter FROM Tbl_Skills "
mstr_SQLInstruction = mstr_SQLInstruction & "WHERE (((Tbl_Skills.ShowYesNoFilter)='" & mstr_No & "'));"

ExecuteCommand mstr_SQLInstruction, mstr_Yes

End Sub

Private Sub cmdRemoveOne_Click()
Dim strSelectedItem As String
Dim lngSelectedItemIndex As Long

'On Error Resume Next

If Me.ListNoItems.ListIndex = -1 Then
MsgBox mstr_MsgNoItemToMove, vbInformation, mstr_MsgBoxTitle
Exit Sub
End If

lngSelectedItemIndex = Me.ListNoItems.ListIndex
strSelectedItem = Me.ListNoItems.ItemData(lngSelectedItemIndex)

If Len(Me.ListNoItems.ItemData(lngSelectedItemIndex)) < 1 Then
MsgBox mstr_MsgNoItemToMove, vbInformation, mstr_MsgBoxTitle
Exit Sub
End If

mstr_SQLInstruction = "SELECT Tbl_Skills.KeyID, Tbl_Skills.Skills, tblNames.ShowYesNoFilter, "
mstr_SQLInstruction = mstr_SQLInstruction & "Tbl_Skills.ShowYesNoFilter FROM Tbl_Skills "
mstr_SQLInstruction = mstr_SQLInstruction & "WHERE (((Tbl_Skills.Skills)='" & strSelectedItem & "'));"

ExecuteCommand mstr_SQLInstruction, mstr_Yes
End Sub

Private Sub Form_Current()

End Sub

Private Sub Form_Open(Cancel As Integer)

mstr_SQLInstruction = "SELECT Tbl_Skills.KeyID, Tbl_Skills.Skills, Tbl_Skills.ShowYesNoFilter, "
mstr_SQLInstruction = mstr_SQLInstruction & "Tbl_Skills.ShowYesNoFilter FROM Tbl_Skills "
mstr_SQLInstruction = mstr_SQLInstruction & "WHERE (((Tbl_Skills.ShowYesNoFilter)='" & mstr_No & "')) "
mstr_SQLInstruction = mstr_SQLInstruction & "OR (((Tbl_Skills.ShowYesNoFilter)='" & mstr_Filtered & "'));"

ExecuteCommand mstr_SQLInstruction, mstr_Yes

End Sub

Private Sub ListNoItems_DblClick(Cancel As Integer)
cmdRemoveOne_Click
End Sub

Private Sub ListYesItems_DblClick(Cancel As Integer)
cmdAddOne_Click
End Sub

Private Sub txtFilter_KeyUp(KeyCode As Integer, Shift As Integer)
Dim strFilter As String

strFilter = Me.txtFilter.Text

Select Case KeyCode
Case 8, 46

mstr_SQLInstruction = "SELECT Tbl_Skills.Skills, Tbl_Skills.ShowYesNoFilter FROM Tbl_Skills "
mstr_SQLInstruction = mstr_SQLInstruction & "WHERE (((Tbl_Skills.Skills) Not Like '%" & strFilter & "%') "
mstr_SQLInstruction = mstr_SQLInstruction & "Or ((Tbl_Skills.ShowYesNoFilter) = '" & mstr_Filtered & "'));"

ExecuteCommand mstr_SQLInstruction, mstr_Yes


mstr_SQLInstruction = "SELECT Tbl_Skills.Skills, Tbl_Skills.ShowYesNoFilter FROM Tbl_Skills "
mstr_SQLInstruction = mstr_SQLInstruction & "WHERE (((Tbl_Skills.Skills) Not Like '%" & strFilter & "%') "
mstr_SQLInstruction = mstr_SQLInstruction & "And ((Tbl_Skills.ShowYesNoFilter) = '" & mstr_Yes & "'));"

ExecuteCommand mstr_SQLInstruction, mstr_Filtered

Case Else
mstr_SQLInstruction = "SELECT Tbl_Skills.Skills, Tbl_Skills.ShowYesNoFilter FROM Tbl_Skills "
mstr_SQLInstruction = mstr_SQLInstruction & "WHERE (((Tbl_Skills.Skills) Not Like '%" & strFilter & "%') "
mstr_SQLInstruction = mstr_SQLInstruction & "And ((Tbl_Skills.ShowYesNoFilter) = '" & mstr_Yes & "'));"

ExecuteCommand mstr_SQLInstruction, mstr_Filtered
End Select

End Sub
Reply With Quote
  #4 (permalink)  
Old 08-02-11, 17:11
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 3,446
Did you check the reference to the ADODB library?
__________________
Have a nice day!
Reply With Quote
  #5 (permalink)  
Old 08-02-11, 17:12
ctown ctown is offline
Registered User
 
Join Date: Jul 2011
Location: Chicago
Posts: 37
Quote:
Originally Posted by Sinndho View Post
Can you please post the code you use in the database and if possible, indicate the line that causes the error. Seeing the code on the site you mention, the first thing that comes to my mind is that your database needs a reference to the ADODB library.
As for what line is causing the error, I would say definitely the 'AddSingle' and 'AddAll', because I get that error when trying to move an item to the other list box.
Reply With Quote
  #6 (permalink)  
Old 08-02-11, 17:14
ctown ctown is offline
Registered User
 
Join Date: Jul 2011
Location: Chicago
Posts: 37
Quote:
Originally Posted by Sinndho View Post
Did you check the reference to the ADODB library?
I honestly don't have any idea what that is. I'm not knowledgable of anything programming related. As you can see on the link I sent, there was nothing in the instruction which said to reference the ADODB library.
Reply With Quote
  #7 (permalink)  
Old 08-02-11, 17:24
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
Quote:
Originally Posted by ctown View Post
I honestly don't have any idea what that is. I'm not knowledgable of anything programming related. As you can see on the link I sent, there was nothing in the instruction which said to reference the ADODB library.
so why not go back to the original source for this code and ask them what is missing or corrupt

the easiest (but not quickest) fix will be to comment out the code for the on click events
then uncomment out lines / sections till the error reappears, then you know where to problem is.

as an alternative open the form in design mode, then try to compile it.. if there are compilation errors that could cause the errors you report
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #8 (permalink)  
Old 08-02-11, 17:30
ctown ctown is offline
Registered User
 
Join Date: Jul 2011
Location: Chicago
Posts: 37
Quote:
Originally Posted by healdem View Post
so why not go back to the original source for this code and ask them what is missing or corrupt

the easiest (but not quickest) fix will be to comment out the code for the on click events
then uncomment out lines / sections till the error reappears, then you know where to problem is.

as an alternative open the form in design mode, then try to compile it.. if there are compilation errors that could cause the errors you report
I would totally do that but it seems the comments section is closed and noone has posted anything on it since 2010.

How would I compile it?
Reply With Quote
  #9 (permalink)  
Old 08-02-11, 18:18
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
should be an option in the VBA window
taking a wild guess that will be tools | compile
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #10 (permalink)  
Old 08-02-11, 18:26
Missinglinq Missinglinq is offline
Registered User
 
Join Date: Jun 2005
Location: Richmond, Virginia USA
Posts: 1,702
I agree with Sinndho, this sounds like a Missing Reference problem. If you haven't done this before, here are Doug Steele's detailed instructions on how to troubleshoot the problem:

Access Reference Problems

Linq ;0)>
__________________
Hope this helps!

The Devil's in the Details!!

All posts/responses based on Access 2000/2003
Reply With Quote
  #11 (permalink)  
Old 08-03-11, 10:08
ctown ctown is offline
Registered User
 
Join Date: Jul 2011
Location: Chicago
Posts: 37
When I click compile, it gives a message "User defined type not defined" and highlights "mobj_ADODBRecordset As ADODB.Recordset"

I'll check out the link you sent to see if I can troubleshoot this. If anyone can think of a simpler solution that would be great.
Reply With Quote
  #12 (permalink)  
Old 08-03-11, 10:13
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 3,446
As far as you want to use objects from a library, there is no simpler solution than creating a reference to it.
__________________
Have a nice day!
Reply With Quote
  #13 (permalink)  
Old 08-03-11, 10:15
ctown ctown is offline
Registered User
 
Join Date: Jul 2011
Location: Chicago
Posts: 37
I appreciate the help with this. If I run into any other issues I'll make sure to let you guys know. Thanks so much.

Now, here goes nothing.
Reply With Quote
  #14 (permalink)  
Old 08-03-11, 11:19
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 3,446
You're welcome!
__________________
Have a nice day!
Reply With Quote
  #15 (permalink)  
Old 08-03-11, 11:31
ctown ctown is offline
Registered User
 
Join Date: Jul 2011
Location: Chicago
Posts: 37
From what I've read on the article about References, it would seem that the code may not work given that it wasn't created on the workstation I'm currently using. Not sure if I can edit this and change it so that it works for the DB i'm creating. But it would seem I need to build the code from scratch, possibly. Is there any alternatives someone can provide so that I can get this to work. I can provide any info necessary to help take me through the steps of creating a code that will get the listboxes to function properly.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On