J
jderrig
I am receiviing a runtime error for the following code.
The CHSAcctNo mainly contains numerals but there are several that end in X.
When I try to select those specific accounts with the X, a run time error
pops up "This key is already associated with an element of this collection."
Do I need something in addition to alllow it to select those accounts as well?
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 Command13_Click()
Debug.Print "Lynn's P&L = " & Me.CHSAcctNo
If IsChecked(Me.CHSAcctNo) = False Then
colCheckBox.Add CStr(Me.CHSAcctNo), CStr(Me.CHSAcctNo)
Else
colCheckBox.Remove (CStr(Me.CHSAcctNo))
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 = "CHSAcctNo in (" & strWhere & ")"
End If
DoCmd.OpenReport "Lynn's P&L", 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
The CHSAcctNo mainly contains numerals but there are several that end in X.
When I try to select those specific accounts with the X, a run time error
pops up "This key is already associated with an element of this collection."
Do I need something in addition to alllow it to select those accounts as well?
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 Command13_Click()
Debug.Print "Lynn's P&L = " & Me.CHSAcctNo
If IsChecked(Me.CHSAcctNo) = False Then
colCheckBox.Add CStr(Me.CHSAcctNo), CStr(Me.CHSAcctNo)
Else
colCheckBox.Remove (CStr(Me.CHSAcctNo))
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 = "CHSAcctNo in (" & strWhere & ")"
End If
DoCmd.OpenReport "Lynn's P&L", 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