Results 1 to 9 of 9

Thread: Button Issues

  1. #1
    Join Date
    Mar 2004
    Posts
    361

    Unanswered: Button Issues

    I have a form that queries info off a table into a bunch of text boxes. I also have 3 buttons on this form. One button is the exit the form at any point. One button is to update the table with information which is added by the user. The last button is to preview a report with the data in the form. What I would like to have happen is this. Once the user completes the form, he/she presses the "show report" button which launches the report and closes the form as well as updating the table. I got the exit button to work fine. So, somehow I need to merge the last two part of the code below so it works with one click. Take a look and see if you can help. Thanks.


    Option Compare Database

    Private Sub Button10_Click()

    Dim strResp As String

    If Me.Dirty = True Then
    strResp = MsgBox("Do you want to save these changes?", vbYesNo, "Save?")

    If strResp = vbNo Then
    Me.Undo
    End If
    End If

    DoCmd.Close
    End Sub
    Private Sub Command377_Click()
    On Error GoTo Err_Command377_Click

    Dim stDocName As String

    stDocName = "Term Worksheet Report"
    DoCmd.OpenReport stDocName, acPreview

    Exit_Command377_Click:
    Exit Sub

    Err_Command377_Click:
    MsgBox Err.Description
    Resume Exit_Command377_Click

    End Sub
    Private Sub Command149_Click()
    On Error GoTo Err_Command149_Click

    DoCmd.GoToRecord , , acNewRec
    DoCmd.GoToControl "txtLeaseNum"

    Exit_Command149_Click:
    Exit Sub

    Err_Command149_Click:
    MsgBox Err.Description
    Resume Exit_Command149_Click

    End Sub

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Code:
    Private Sub Button10_Click()
    
    Dim strResp As String
    
    If Me.Dirty = True Then
       strResp = MsgBox("Do you want to save these changes?", vbYesNo, "Save?")
       If strResp = vbNo Then
          Me.Undo
       End If
    End If
    
        Dim stDocName As String
    
        stDocName = "Term Worksheet Report"
        DoCmd.OpenReport stDocName, acPreview
    
        DoCmd.GoToRecord , , acNewRec
        DoCmd.GoToControl "txtLeaseNum"
    
     DoCmd.Close
        
    End Sub
    ?
    oh yeah... documentation... I have heard of that.

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

  3. #3
    Join Date
    Mar 2004
    Posts
    361
    close, but this is what I need. I need the exit button to be a stand alone. Meaning if the user wants to leave the form at any time he can. The other button will update the table and then open the query. Any clues?

  4. #4
    Join Date
    Mar 2004
    Posts
    361
    This is part of the code I am trying to fix.

    Private Sub Command149_Click()
    On Error GoTo Err_Command149_Click


    DoCmd.GoToRecord , , acNewRec
    DoCmd.GoToControl "txtLeaseNum"

    Exit_Command149_Click:
    Exit Sub

    Err_Command149_Click:
    MsgBox Err.Description
    Resume Exit_Command149_Click
    End If

    Dim stDocName As String

    stDocName = "Term Worksheet Report"
    DoCmd.OpenReport stDocName, acPreview

    DoCmd.GoToRecord , , acNewRec
    DoCmd.GoToControl "txtLeaseNum"


    End Sub

  5. #5
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Do you not understand how that code works?

    That was quite obviously created by a wizard.
    oh yeah... documentation... I have heard of that.

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

  6. #6
    Join Date
    Mar 2004
    Posts
    361
    I actually have no idea how code works. I am doing this as a favor to a person who have never used access before. I feel like the code is close but it just needs a little tweaking.

  7. #7
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    I figured as much.

    You only need to remove one line of code for it to function properly.

    Figure out how it works.
    oh yeah... documentation... I have heard of that.

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

  8. #8
    Join Date
    Mar 2004
    Posts
    361
    I took out each line an tried it but the report never launched. The button updates the record but that's it. Could you at least give me a hint?

  9. #9
    Join Date
    Mar 2004
    Posts
    361
    This is what I have now. The exit button works fine and the update part of the code work but it just doesn't launch the report. Anu clues?

    Option Compare Database


    Private Sub Button10_Click()

    Dim strResp As String

    If Me.Dirty = True Then
    strResp = MsgBox("Do you want to save these changes?", vbYesNo, "Save?")
    If strResp = vbNo Then
    Me.Undo
    End If
    End If
    DoCmd.Close
    End Sub

    Private Sub Command149_Click()
    On Error GoTo Err_Command149_Click

    DoCmd.GoToControl "txtLeaseNum"
    DoCmd.GoToRecord , , acNewRec

    Exit_Command149_Click:
    Exit Sub

    Err_Command149_Click:
    MsgBox Err.Description
    Resume Exit_Command149_Click


    Dim stDocName As String

    stDocName = "Term Worksheet Report"
    DoCmd.OpenReport stDocName, acPreview

    DoCmd.GoToRecord , , acNewRec
    DoCmd.GoToControl "txtLeaseNum"


    End Sub

Posting Permissions

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