Results 1 to 6 of 6

Thread: List Box

  1. #1
    Join Date
    Sep 2004
    Posts
    33

    Unanswered: List Box

    I have a Form and in that form I have many command buttons. Instead of command buttons I want to make it simple and create a list box.

    Instead of findign the corret command button first from the "list box" I want to choose tha option I want and press execute button to view the report.

    here is my code embedded inside the form how can i change it just to use one list box and a execute button

    thanks in advance if you can help me

    PHP Code:
    Option Compare Database
    Option Explicit


    Private Sub Form_Current()
        If 
    IsNull(Me![CustomerID]) Then
          DoCmd
    .GoToControl "BillingAddress"
        
    End If
    End Sub
    Private Sub Form_Activate()
    On Error GoTo Err_Form_Activate
        Me
    ![Orders by Customer Subform].Requery

    Exit_Form_Activate
    :
        Exit 
    Sub

    Err_Form_Activate
    :
        
    MsgBox Err.Description
        Resume Exit_Form_Activate
    End Sub
    Private Sub Orders_Click()
    On Error GoTo Err_Orders_Click
        
    If IsNull(Me![CustomerID]) Then
            MsgBox 
    "Enter customer information before entering order."
        
    Else
            
    DoCmd.DoMenuItem acFormBaracRecordsMenuacSaveRecord, , acMenuVer70
            DoCmd
    .OpenForm "Orders", , , , acEdit
        End 
    If

    Exit_Orders_Click:
        Exit 
    Sub

    Err_Orders_Click
    :
        
    MsgBox Err.Description
        Resume Exit_Orders_Click
    End Sub
    Private Sub Payments_Click()
    On Error GoTo Err_Payments_Click
        
    If Forms![Orders by Customer]![Orders by Customer Subform].Form.RecordsetClone.RecordCount 0 Then
            MsgBox 
    "Enter order information before viewing payments form."
        
    Else
            
    DoCmd.DoMenuItem acFormBaracRecordsMenuacSaveRecord, , acMenuVer70
            DoCmd
    .OpenForm "Payments", , , "[OrderID] = Forms![Orders by Customer]![Orders by Customer Subform].form![OrderID]"
        
    End If

    Exit_Payments_Click:
        Exit 
    Sub

    Err_Payments_Click
    :
        
    MsgBox Err.Description
        Resume Exit_Payments_Click
    End Sub
    Private Sub PreviewInvoice_Click()
    On Error GoTo Err_PreviewInvoice_Click
        
    If Forms![Orders by Customer]![Orders by Customer Subform].Form.RecordsetClone.RecordCount 0 Then
            MsgBox 
    "Enter order information before previewing invoice."
        
    Else
            
    DoCmd.DoMenuItem acFormBaracRecordsMenuacSaveRecord, , acMenuVer70
            DoCmd
    .OpenReport "Invoice"acPreview, , "[OrderID] = Forms![Orders by Customer]![Orders by Customer Subform].form![OrderID]"
        
    End If

    Exit_PreviewInvoice_Click:
        Exit 
    Sub

    Err_PreviewInvoice_Click
    :
        If 
    Err <> 2501 Then
            MsgBox Err
    .Description
        End 
    If
        
    Resume Exit_PreviewInvoice_Click
    End Sub

    Private Sub PreviewInvoice_Order_ready_Click()
    On Error GoTo Err_PreviewInvoice_Order_ready_Click
        
    If Forms![Orders by Customer]![Orders by Customer Subform].Form.RecordsetClone.RecordCount 0 Then
            MsgBox 
    "Enter order information before previewing invoice."
        
    Else
            
    DoCmd.DoMenuItem acFormBaracRecordsMenuacSaveRecord, , acMenuVer70
            DoCmd
    .OpenReport "Invoice_Order_ready"acPreview, , "[OrderID] = Forms![Orders by Customer]![Orders by Customer Subform].form![OrderID]"
        
    End If

    Exit_PreviewInvoice_Order_ready_Click:
        Exit 
    Sub

    Err_PreviewInvoice_Order_ready_Click
    :
        If 
    Err <> 2501 Then
            MsgBox Err
    .Description
        End 
    If
        
    Resume Exit_PreviewInvoice_Order_ready_Click
    End Sub


    Private Sub PreviewInvoice_Ilksen_Click()
    On Error GoTo Err_PreviewInvoice_Ilksen_Click
        
    If Forms![Orders by Customer]![Orders by Customer Subform].Form.RecordsetClone.RecordCount 0 Then
            MsgBox 
    "Enter order information before previewing invoice."
        
    Else
            
    DoCmd.DoMenuItem acFormBaracRecordsMenuacSaveRecord, , acMenuVer70
            DoCmd
    .OpenReport "Invoice_Ilksen"acPreview, , "[OrderID] = Forms![Orders by Customer]![Orders by Customer Subform].form![OrderID]"
        
    End If

    Exit_PreviewInvoice_Ilksen_Click:
        Exit 
    Sub

    Err_PreviewInvoice_Ilksen_Click
    :
        If 
    Err <> 2501 Then
            MsgBox Err
    .Description
        End 
    If
        
    Resume Exit_PreviewInvoice_Ilksen_Click
    End Sub

    Private Sub PreviewInvoice_Shipment_Click()
    On Error GoTo Err_PreviewInvoice_Shipment_Click
        
    If Forms![Orders by Customer]![Orders by Customer Subform].Form.RecordsetClone.RecordCount 0 Then
            MsgBox 
    "Enter order information before previewing invoice."
        
    Else
            
    DoCmd.DoMenuItem acFormBaracRecordsMenuacSaveRecord, , acMenuVer70
            DoCmd
    .OpenReport "Invoice_Shipment"acPreview, , "[OrderID] = Forms![Orders by Customer]![Orders by Customer Subform].form![OrderID]"
        
    End If

    Exit_PreviewInvoice_Shipment_Click:
        Exit 
    Sub

    Err_PreviewInvoice_Shipment_Click
    :
        If 
    Err <> 2501 Then
            MsgBox Err
    .Description
        End 
    If
        
    Resume Exit_PreviewInvoice_Shipment_Click
    End Sub

    Private Sub PreviewInvoice_Proforma_Click()
    On Error GoTo Err_PreviewInvoice_Proforma_Click
        
    If Forms![Orders by Customer]![Orders by Customer Subform].Form.RecordsetClone.RecordCount 0 Then
            MsgBox 
    "Enter order information before previewing invoice."
        
    Else
            
    DoCmd.DoMenuItem acFormBaracRecordsMenuacSaveRecord, , acMenuVer70
            DoCmd
    .OpenReport "Invoice_Proforma"acPreview, , "[OrderID] = Forms![Orders by Customer]![Orders by Customer Subform].form![OrderID]"
        
    End If

    Exit_PreviewInvoice_Proforma_Click:
        Exit 
    Sub

    Err_PreviewInvoice_Proforma_Click
    :
        If 
    Err <> 2501 Then
            MsgBox Err
    .Description
        End 
    If
        
    Resume Exit_PreviewInvoice_Proforma_Click
    End Sub
    Private Sub PreviewInvoiceRECORDS_Click()
    On Error GoTo Err_PreviewInvoiceRECORDS_Click
        
    If Forms![Orders by Customer]![Orders by Customer Subform].Form.RecordsetClone.RecordCount 0 Then
            MsgBox 
    "Enter order information before previewing invoice."
        
    Else
            
    DoCmd.DoMenuItem acFormBaracRecordsMenuacSaveRecord, , acMenuVer70
            DoCmd
    .OpenReport "InvoiceRECORDS"acPreview, , "[OrderID] = Forms![Orders by Customer]![Orders by Customer Subform].form![OrderID]"
        
    End If

    Exit_PreviewInvoiceRECORDS_Click:
        Exit 
    Sub

    Err_PreviewInvoiceRECORDS_Click
    :
        If 
    Err <> 2501 Then
            MsgBox Err
    .Description
        End 
    If
        
    Resume Exit_PreviewInvoiceRECORDS_Click
    End Sub

    Private Sub PreviewInvoice_Envelope_Click()
    On Error GoTo Err_PreviewInvoice_Envelope_Click
        
    If Forms![Orders by Customer]![Orders by Customer Subform].Form.RecordsetClone.RecordCount 0 Then
            MsgBox 
    "Enter order information before previewing invoice."
        
    Else
            
    DoCmd.DoMenuItem acFormBaracRecordsMenuacSaveRecord, , acMenuVer70
            DoCmd
    .OpenReport "Invoice_Envelope"acPreview, , "[OrderID] = Forms![Orders by Customer]![Orders by Customer Subform].form![OrderID]"
        
    End If

    Exit_PreviewInvoice_Envelope_Click:
        Exit 
    Sub

    Err_PreviewInvoice_Envelope_Click
    :
        If 
    Err <> 2501 Then
            MsgBox Err
    .Description
        End 
    If
        
    Resume Exit_PreviewInvoice_Envelope_Click
    End Sub

    Private Sub PreviewInvoiceTR_Click()
    On Error GoTo Err_PreviewInvoiceTR_Click
        
    If Forms![Orders by Customer]![Orders by Customer Subform].Form.RecordsetClone.RecordCount 0 Then
            MsgBox 
    "Enter order information before previewing invoice."
        
    Else
            
    DoCmd.DoMenuItem acFormBaracRecordsMenuacSaveRecord, , acMenuVer70
            DoCmd
    .OpenReport "InvoiceTR"acPreview, , "[OrderID] = Forms![Orders by Customer]![Orders by Customer Subform].form![OrderID]"
        
    End If

    Exit_PreviewInvoiceTR_Click:
        Exit 
    Sub

    Err_PreviewInvoiceTR_Click
    :
        If 
    Err <> 2501 Then
            MsgBox Err
    .Description
        End 
    If
        
    Resume Exit_PreviewInvoiceTR_Click
    End Sub

    Private Sub findbutton_Click()
    On Error GoTo Err_findbutton_Click


        Screen
    .PreviousControl.SetFocus
        DoCmd
    .DoMenuItem acFormBaracEditMenu10, , acMenuVer70

    Exit_findbutton_Click
    :
        Exit 
    Sub

    Err_findbutton_Click
    :
        
    MsgBox Err.Description
        Resume Exit_findbutton_Click
        
    End Sub
    Private Sub Combo56_AfterUpdate()
        
    ' Find the record that matches the control.
        Dim rs As Object

        Set rs = Me.Recordset.Clone
        rs.FindFirst "[CustomerID] = " & Str(Nz(Me![Combo56], 0))
        If Not rs.EOF Then Me.Bookmark = rs.Bookmark
    End Sub 

  2. #2
    Join Date
    Sep 2004
    Posts
    161
    You can try this
    Code:
    Private Sub Cmd_Ok_Click()
    Dim Indice As Variant
    '
    For Each Indice In List_Box.ItemsSelected
        DoCmd.OpenForm "xxxxxx", acNormal, , , , , _
        List_Box.Column(0, Indice)
    Next Indice
    
    End Sub

  3. #3
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    So what are you saying here... you have a bunch of command buttons you want "converted" to a listbox?

    There's a few ways to do that. You could use a case statement to figure out which listbox selection is current. You could use a multi-column listbox and store the name of the form you'd like to open as pertains to each selection. You could create a table of report names and reference that by display name... all sorts of options...
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  4. #4
    Join Date
    Aug 2003
    Location
    Cleveland USA
    Posts
    184

    Smile

    Don't know the exact code, but you could create a table that contains the actual report names in one column and descriptive names in the second. The listbox or combo box could be based on this table.

    Here's some psuedo-psuedocode for what I'm suggesting:

    strFormName = Comboboxname.selected

    If <<Code here to determine if the user entered the necessary criteria>>
    Then:
    Docmd.OpenForm strFormName,<<other criteria set>>
    Else
    MsgBox "You are missing some criteria"
    Exit Sub
    End If

  5. #5
    Join Date
    Aug 2003
    Location
    Cleveland USA
    Posts
    184
    I forgot to ask- can they run only one report at a time? If so, you might want to choose a combo box instead since you can have only one choice selected at a time.

  6. #6
    Join Date
    Sep 2004
    Posts
    33
    yes I can open only one report at a time.I think I need combo box (like choosing the country in a form whihc we see in web sites.)..i am really a beginner in access do you guys have an example database so I can see and edit it to my way

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •