Code 13 Error

freezeb

Registered User.
Local time
Today, 03:47
Joined
Sep 13, 2010
Messages
17
I have a string in my code that keeps getting a code 13 error message when I run from my form. The form has a list box that displays and index field called testdetails_id which is an auto number field in testdetails_tbl. The 2nd field is called drawings which is part of drawings_tbl and is a text field which are linked in the testdetails_tbl by the drawing_id. I am getting the information for the list box from a query that takes in the the 3 tables. The data displayed is correct with regards to the drawings and test packages. My problem is when I run this code to delete selected drawings from the testdetails_tbl it errors say Type Mismatch on this string.

strIn = strIn & Me.List9!TestDetails_ID & ","

List9 is the correct list box. The full code used in the Event Procedure is:

Dim strIn As String
Dim varItm As Variant
Dim strSQL As String

For Each varItm In Me.List9.ItemsSelected
strIn = strIn & Me.List9!TestDetails_ID & ","
Next

strIn = Left(strIn, Len(strIn) - 1)
strIn = " Where [testdetails_id] In (" & strIn & ")"

strSQL = "DELETE * FROM testpackdetails_tbl" & strIn

CurrentDb.Execute strSQL, dbFailOnError

Very Perplexed with this one.
 
How many columns are in the list box? Have you tried using this alternative:
Code:
Me.List9.Column(IndexNum) & ","
Listbox Column Indexes start at 0. E.g. - If one column is in the box, to return the selected value:
Code:
Me.List9.Column(0)
 
I believe what you want is:
Code:
For Each varItm In Me.List9.ItemsSelected
    strIn = strIn & [COLOR=Blue][B]Me.List9.ItemData(varItm)[/B][/COLOR] & ","
Next
 
I tried both suggestions with the same error on the 1st suggestion. The 2nd one which was from "vbaInet" gives me the following VB Script error. I brings up the debug and "Run Time Error 3061 to few parameters. Expected 1"
For Each varItm In Me.List9.ItemsSelected strIn = strIn & Me.List9.ItemData(varItm) & "," Next
 
I tried both suggestions with the same error on the 1st suggestion. The 2nd one which was from "vbaInet" gives me the following VB Script error. I brings up the debug and "Run Time Error 3061 to few parameters. Expected 1"
For Each varItm In Me.List9.ItemsSelected strIn = strIn & Me.List9.ItemData(varItm) & "," Next


Have you hovered your mouse over the code after it executes (if that's possible)? have you tried using the cstr() conversion on the variant that comes out of the "itemdata" property?

Have you looked up error 3061 in the help menu for possible causes? could the varItm variable be out of scope? Probably not though, otherwise you'd get a different error.
 
Also, just to clarify a few things:

The 2nd one which was from "vbaInet" gives me the following VB Script error.
Are we talking about VB Script or VBA here?

The other thing is are you sure your listbox is a multiselect listbox?

If this is VBA and your code isn't working then here's an alternative:
Code:
dim i as integer

for i = 0 to me.lst9.listcount - 1
     if me.lst9.selected(i) = true then
           strIn = strIn & me.lst9.column(0, i) & ","
     end if
next
 

Users who are viewing this thread

Back
Top Bottom