Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2007
    Posts
    7

    Unanswered: Password Protected Button

    Nothing happens when I click the button...Any Suggestions?
    Code:
    Private Sub cmdReport_Click()
        On Error GoTo Err_cmdReport_Click
    
        Dim strReport As String
        Dim strPW As String
        Dim strGetPWReq As String
    
        strReport = Me.listReport.Column(0)
        strPW = Me.listReport.Column(6)
          
            
        If Len(Me.txtdatefrom & vbNullString) = 0 Or Len(Me.txtDateTo & vbNullString) = 0 Then
                MsgBox "Please Select A Date Range!", _
                vbInformation, "Required Data..."
                Exit Sub
        Else
    
            If Me.listReports.Column(5) = -1 Then
    
               strGetPWReq = InputBox("Enter Password")
                    If strGetPWReq = strPW Then
                        DoCmd.OpenReport strReport, acViewReport
                        DoCmd.Maximize
                    Else
                        MsgBox "Incorrect Password"
                        Exit Sub
                    End If
             Else
                DoCmd.OpenReport strReport, acViewReport
                DoCmd.Maximize
            End If
        End If
            
    Exit_cmdReport_Click:
        Exit Sub
    
    Err_cmdReport_Click:
        MsgBox Err.Description
        Resume Exit_cmdReport_Click
    End Sub
    Last edited by gvee; 01-09-08 at 12:18. Reason: [CODE] tags added for readability

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    if you set a breakpoint on the button code does the break point trigger?

    its possible in access to write code which isn't recognised by the IDE.. the fix is to make sure the correct event is checked in the form designer | properties | events tab

    if it does trigger a breakpoint, walk trhough the code untill you find what is happening

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Try:
    Code:
    If Me.listReports.Column(5) = "-1" Then
    Your if structure is confusing and messy too; you may wish to consider re-writing it in part.

    EDIT: I have updated your post with [CODE] tags for readability; which has made things a lot clearer.
    The bit I dislike is
    Code:
                Exit Sub
        Else
    Instead of an else that should be an End If IMO
    George
    Home | Blog

  4. #4
    Join Date
    Dec 2007
    Posts
    7
    Thanks for the replies.

    As far as re-writing the code...could you provide more feedback please. I am in the beginning stages of learning code, and most of that was done via copy paste and a little editing. I would appreciate any advice. Thanks.

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    If you have copied and pasted the code I'd strongly suspect the code isn't actually triggering, a common problem, especially if the code has been written without direct reference to the form design

    open the form in design mode
    select the relevant control, select the properties look for the event tab and make sure the on click event says [event procedure]

  6. #6
    Join Date
    Dec 2007
    Posts
    7
    The OnClick event is set correctly (event procedure)

    I had this code in previously, and it works perfect, the problem comes when I try to check the report selection to determine if a password is requiring, and then triggering a password inputbox if the password is required.

    Private Sub cmdReport_Click()
    On Error GoTo Err_cmdReport_Click

    Dim strReport As String

    strReport = Me.listReport.Column(0)


    If Len(Me.txtdatefrom & vbNullString) = 0 Or Len(Me.txtDateTo & vbNullString) = 0 Then
    MsgBox "Please Select A Date Range!", _
    vbInformation, "Required Data..."
    Exit Sub
    Else
    DoCmd.OpenReport strReport, acViewReport
    DoCmd.Maximize
    End If

    Exit_cmdReport_Click:
    Exit Sub

    Err_cmdReport_Click:
    MsgBox Err.Description
    Resume Exit_cmdReport_Click
    End Sub

  7. #7
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    ok so have you set a break point and stepped through the code to find where it is going wrong?


    open the form in design mode, select view code
    select the leftmost vertical box adjacent to "Private Sub cmdReport_Click()", you should then see a disc appear, run the form and see what happens

  8. #8
    Join Date
    Dec 2007
    Posts
    7
    I click the vertical box/bar next to private sub....a red circle appears...I run the form and nothing happens when i click the view report button.

  9. #9
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    ok so what you have is a piece of code that isn't associated with a specific access event.

    what you could try doing is double clciking the control in design mode and pull up the build event action. it may be a single right click, this pc doesn't have access on so can't be specific

    that should then open the code window... see if that opens up the code you have already typed in, if not add the code there....

    failing that I'd consider a complete recompile, failing that i'd do a compoact and repair

    HTH

  10. #10
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    possible route:
    edit
    Private Sub cmdReport_Click()
    to
    Private Sub nuffink()
    then
    use the combos at the top of the code window to create a new click event for the button cmdReport

    copy/paste the code (not the private.... and not the end sub lines) from nuffink to your new cmdReport_Click() event procedure.

    izy
    currently using SS 2008R2

Posting Permissions

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