Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2005
    Posts
    240

    Unanswered: Problem with Listbox on form

    Hi

    I need some help regarding a listbox on a form. I have created a form based on a table with a Booking_ID and an Employer_ID (the Booking_ID is the PK).
    The Employer_ID links to the name and address of an employer.

    What I want to do is create a booking using this form. I created a listbox using the wizard to list the name of the employers, and store the employer ID in the textbox on the form.

    I have created three buttons on the form, one to add a booking to the employer, one to view all of the employers bookings and one to close the form. The problem is it adds a record even if I click the view all bookings button or the close form button.

    I just want it to add a record when I click the add booking button.

    This is the code behind the add booking button:

    Code:
    Private Sub cmdAdd_Click()
    On Error GoTo Err_cmdAdd_Click
    
        Dim stDocName As String
        Dim stLinkCriteria As String
    
        stDocName = "frmConferencing"
        
        stLinkCriteria = "[Emp_ID]=" & Me![Emp_ID]
        DoCmd.GoToRecord , , acNewRec
        DoCmd.OpenForm stDocName, , , stLinkCriteria
        
    Exit_cmdAdd_Click:
        Exit Sub
    
    Err_cmdAdd_Click:
        MsgBox Err.Description
        Resume Exit_cmdAdd_Click
        
    End Sub
    Code behind View Bookings button:

    Code:
    Private Sub cmdVwBooking_Click()
    On Error GoTo Err_cmdVwBooking_Click
    
        Dim stDocName As String
        Dim stLinkCriteria As String
    
        stDocName = "frmConferencing"
        
        stLinkCriteria = "[Emp_ID]=" & Me![Emp_ID]
        DoCmd.OpenForm stDocName, , , stLinkCriteria
    
    Exit_cmdVwBooking_Click:
        Exit Sub
    
    Err_cmdVwBooking_Click:
        MsgBox Err.Description
        Resume Exit_cmdVwBooking_Click
        
    End Sub
    Is there any way I can stop it adding records when I click the other buttons?

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    What is the code behind the "other buttons"?
    oh yeah... documentation... I have heard of that.

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

  3. #3
    Join Date
    Sep 2005
    Posts
    240
    The only other button on the form is a standard Close Form button.

    I tried created a DAO Recordset and adding the records in to the listbox that way, it kinda worked, but leaves a large space before displaying any of the records, and also doesn't display some of them.

Posting Permissions

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