Question : microsoft access vba code to select objects from a combo box

I have the following code that works well in selecting objects (tables, forms, reports, etc) from a list box.  However, I run into problems when using the same logic for selecting items from a combo box.  The code below is for a list box and I was requesting expert help in adapting it to a combo box.  Thanks.  My combo box is called Combo1.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
Private Sub ScrapSinceOK_Click()

'DoCmd.RunMacro "DialogOK"

Me.Visible = True
On Error GoTo Err_ScrapSinceOK_Click

    Dim x As Variant, strObject As Long, strObject1 As Long, strObject3 As Long, strObject4 As Long, strObject5 As Long, obj As AccessObject
    For Each x In InternalAuditScheduleList.ItemsSelected
        strObject = InternalAuditScheduleList.Column(1, x)
        Select Case strObject
            Case 1 'acTable
                'Set obj = CurrentData.AllTables
                DoCmd.OpenTable InternalAuditScheduleList.ItemData(x), acViewNormal
            Case 4 'acTable
                'Set obj = CurrentData.AllTables
                DoCmd.OpenTable InternalAuditScheduleList.ItemData(x), acViewNormal
            Case 6 'acTable
                'Set obj = CurrentData.AllTables
                DoCmd.OpenTable InternalAuditScheduleList.ItemData(x), acViewNormal
            Case 5 'acQuery
                'Set obj = CurrentData.AllQueries
                DoCmd.OpenQuery InternalAuditScheduleList.ItemData(x), acViewNormal
                '    DoCmd.OpenQuery obj, acViewNormal
                '    DoCmd.OpenQuery strObject, acViewNormal
            Case -32768 'acForm
                'Set obj = CurrentProject.AllForms
               DoCmd.OpenForm InternalAuditScheduleList.ItemData(x), acViewNormal
            Case -32764 'acReport
                'Set obj = CurrentProject.AllReports
              DoCmd.OpenReport InternalAuditScheduleList.ItemData(x), acViewPreview

            Case -32766 'acMacro
                'Set obj = CurrentProject.AllMacros
            DoCmd.RunMacro InternalAuditScheduleList.ItemData(x)
            'Case acModule
                'Set obj = CurrentProject.AllModules
            'Case acDataAccessPage
                'Set obj = CurrentProject.AllDataAccessPages
        End Select
    Next
 
Exit_ScrapSinceOK_Click:
    Exit Sub
 
Err_ScrapSinceOK_Click:
    MsgBox err.Description
    Resume Exit_ScrapSinceOK_Click
    
End Sub

Answer : microsoft access vba code to select objects from a combo box

remove this line

For Each x In InternalAuditScheduleList
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
Private Sub ScrapSinceOK_Click()

'DoCmd.RunMacro "DialogOK"

Me.Visible = True
On Error GoTo Err_ScrapSinceOK_Click

Dim x As Variant, strObject As Long, strObject1 As Long, strObject3 As Long, strObject4 As Long, strObject5 As Long, obj As AccessObject
Dim j
With Me.InternalAuditScheduleList
    For j = 0 To .ListCount - 1

            strObject = .Column(1, j)
            Select Case strObject
                Case 1 'acTable
                'Set obj = CurrentData.AllTables
                    DoCmd.OpenTable InternalAuditScheduleList.ItemData(x), acViewNormal
                Case 4 'acTable
                    'Set obj = CurrentData.AllTables
                    DoCmd.OpenTable InternalAuditScheduleList.ItemData(x), acViewNormal
                Case 6 'acTable
                    'Set obj = CurrentData.AllTables
                    DoCmd.OpenTable InternalAuditScheduleList.ItemData(x), acViewNormal
                Case 5 'acQuery
                    'Set obj = CurrentData.AllQueries
                    DoCmd.OpenQuery InternalAuditScheduleList.ItemData(x), acViewNormal
                    '    DoCmd.OpenQuery obj, acViewNormal
                    '    DoCmd.OpenQuery strObject, acViewNormal
                Case -32768 'acForm
                    'Set obj = CurrentProject.AllForms
                    DoCmd.OpenForm InternalAuditScheduleList.ItemData(x), acViewNormal
                Case -32764 'acReport
                    'Set obj = CurrentProject.AllReports
                    DoCmd.OpenReport InternalAuditScheduleList.ItemData(x), acViewPreview
                Case -32766 'acMacro
                    'Set obj = CurrentProject.AllMacros
                    DoCmd.RunMacro InternalAuditScheduleList.ItemData(x)
                'Case acModule
                    'Set obj = CurrentProject.AllModules
                'Case acDataAccessPage
                    'Set obj = CurrentProject.AllDataAccessPages
            End Select

    Next
End With
 
Exit_ScrapSinceOK_Click:
    Exit Sub
 
Err_ScrapSinceOK_Click:
    MsgBox err.Description
    Resume Exit_ScrapSinceOK_Click
    
End Sub
Random Solutions  
 
programming4us programming4us