RT Error 5 Multiselect Form

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

Guest

Used this Multiselect before it worked fine.. works on another computer fine
Have it (variations) in 2 mdb and both now return RT Error 5 have read and
tried some of the fixes on the following...
http://www.accessmvp.com/djsteele/AccessReferenceErrors.html

I have checked referances none MISSING /reset etc doesn't fix
Any other "quick" suggestions WHY this would happen? (by the way I am NOOB
so be kind please) following is where the error occurs
Thanks
lmv

Public Function IsChecked(vID As Variant) As Boolean
Dim lngID As Long
IsChecked = False
On Error GoTo exit1
lngID = colCheckBox(CStr(vID))
If lngID <> 0 Then
IsChecked = True
End If
 
Error 5 is "Invalid procedure call or argument"

I'd suspect that it's complaining about the statement:

lngID = colCheckBox(CStr(vID))

What is colCheckBox?

I suspect that's not the entire code for your IsChecked function, since
you've got a On Error GoTo exit1 statement, but no line exit1.
 
Thx for the response:
Here is all of the code... before when I opened it no problem... now ERROR
5...
On this one I never changed anything... it was the way I downloaded it.
Is something corrupt in Access rather than in the code?
-----------
Option Compare Database
Option Explicit

Dim colCheckBox As New Collection


Public Function IsChecked(vID As Variant) As Boolean

Dim lngID As Long

IsChecked = False

On Error GoTo exit1

lngID = colCheckBox(CStr(vID))
If lngID <> 0 Then
IsChecked = True
End If

exit1:

End Function


Private Sub Check11_KeyDown(KeyCode As Integer, Shift As Integer)


If KeyCode = vbKeySpace Then
KeyCode = 0
Call Command13_Click
End If


End Sub

Private Sub cmdEdit_Click()

DoCmd.OpenForm "contacts", , , "Contactid = " & Me.ContactID

End Sub

Private Sub Command13_Click()

'Debug.Print "contact = " & Me.ContactID

If IsChecked(Me.ContactID) = False Then
colCheckBox.Add CLng(Me.ContactID), CStr(Me.ContactID)
Else
colCheckBox.Remove (CStr(Me.ContactID))
End If
Me.Check11.Requery

End Sub

Private Sub Command14_Click()


MsgBox "records selected = " & MySelected, vbInformation, "Multi Select
example"

End Sub

Private Function MySelected() As String


Dim i As Integer

For i = 1 To colCheckBox.Count
If MySelected <> "" Then
MySelected = MySelected & ","
End If
MySelected = MySelected & colCheckBox(i)

Next i


End Function



Private Sub Command16_Click()

Dim strWhere As String

strWhere = MySelected

If strWhere <> "" Then

strWhere = "contactID in (" & strWhere & ")"

End If

DoCmd.OpenReport "Contacts1", acViewPreview, , strWhere
DoCmd.RunCommand acCmdZoom100 ' this is optional


End Sub

Private Sub Command17_Click()

Set colCheckBox = Nothing
Me.Requery


End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

' key hand

Select Case KeyCode

Case vbKeyUp
KeyCode = 0
On Error Resume Next
DoCmd.GoToRecord acActiveDataObject, , acPrevious

Case vbKeyDown
KeyCode = 0
On Error Resume Next
DoCmd.GoToRecord acActiveDataObject, , acNext

' Case vbKeyReturn
' If IsNull(Me.ID) = False Then
' KeyCode = 0
' Call EditMain
' End If

End Select

End Sub
 
Not sure whether it could be an Access problem or not. You could check
whether your References collection is messed up.

Do you know what line the code is failing on?
 
Already cked referances as per 1st post... don't know if there is something
else to try in that area /checked unchecked etc.
Do you know what line the code is failing on?

lngID = colCheckBox(CStr(vID))

thx
lmv
 
Why are you passing the argument as a Variant. Why not pass it as a string,
and avoid the CStr?
 
Why are you passing the argument as a Variant. Why not pass it as a string,
and avoid the CStr?

It was a copied mdb... regarding your question...I don't know the
difference... what can I read to understand it. And for now what do I put
instead?
Thx
lmv
 
I was suggesting:

Public Function IsChecked(sID As String) As Boolean
Dim lngID As Long

IsChecked = False

On Error GoTo exit1

lngID = colCheckBox(sID)
If lngID <> 0 Then
IsChecked = True
End If

exit1:

End Function

Unless there's a possibility that what you're passing could be Null, there's
seldom any reason to use a Variant as an argument. If you were calling the
function from a query, where it might be possible for a field to be Null,
then using a Variant would make sense. In this case, though, you're passing
Me.ContactID. If worse comes to worse, you can check whether that's Null,
rather than passing it to the function.
 
Still get the same error doesn't matter if it is a string or a variable. As
far as the null part of it Sorry I don't understand...

Seems like something has happened... this mdb worked when I downloaded it. I
haven't changed the code or anything... in fact cked the original zip just to
make sure.

I don't know if it matters but the other day I was trying to learn
automation access tto excel and I had used the MS Excel reference ... I had
to shut down and reboot at one point because the process locked up. (This mdb
opens... on my other computer without the error (MS Access 9 olb) Is it
possible that my reference(MSAccess 11) msacc.olb is corrupted or my
registry? Just seems strange that the code worked before and now doesn't...
but then what do I know.
Thanks
lmv
 
Decided to do a system Restore... after my last post... process of elimination.
Fixed the problem must have corrupted something in Access the other day...

Thanks anyway,
lmv
 
Back
Top