Consulting

Results 1 to 4 of 4

Thread: Solved: YesNo Box - Options Query

  1. #1

    Solved: YesNo Box - Options Query

    Hey Guys

    I've written the below as a template for several "log in" choices for a databse (don't get me started on how it could be better if you actually used a database program instead of Excel )

    I would like to have the options "Yes" or "No" changed to "Open a new record" and "Open an existing record" respectively, but seem to be having trouble getting it to work.

    Any ideas?

    [VBA]Sub SELASecurity()
    Application.ScreenUpdating = False
    Answer = MsgBox("What would you like to open a new record?", vbYesNo, "Open SELA Records")
    If Answer = vbNo Then
    PWAnswer = Application.InputBox("Please enter the SELA Database password?")
    If PWAnswer <> Sheets("Security").Range("B2") Then
    Answer = MsgBox("The Password you have entered is incorrect.", vbOK, "ACCESS DENIED")

    If Answer = vbOK Then Exit Sub

    Else:
    Sheets("FIM Complaint Database").Visible = True
    Sheets("Review Existing Record").Select

    End If
    End If
    If Answer = vbYes Then
    PWAnswer = Application.InputBox("Please enter the SELA Database password?")
    If PWAnswer <> Sheets("Security").Range("B2") Then
    Answer = MsgBox("The Password you have entered is incorrect.", vbOK, "ACCESS DENIED")

    If Answer = vbOK Then Exit Sub

    Else:
    Sheets("FIM Complaint Database").Visible = True
    Sheets("New Record").Unprotect Password:=""
    Sheets("New Record").Select
    Range("C6") = "SELA"
    Sheets("New Record").Protect Password:=""
    End If
    End If


    '
    End Sub[/VBA]

    Thanks gents

    Phel x

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You need to create a form with b uttons, not use MsgBox.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You can't change button titles on a standard messagebox. You could create a userfom to resemble one.

    Here's a simplified form of your code which should be easier to follow. Please use Option Explicit and declare your variables.
    [VBA]
    Sub SELASecurity()
    PWAnswer = Application.InputBox("Please enter the SELA Database password?")
    If PWAnswer <> Sheets("Security").Range("B2") Then
    MsgBox "The Password you have entered is incorrect." & vbCr & "ACCESS DENIED"
    Exit Sub
    End If
    Application.ScreenUpdating = False
    Answer = MsgBox("What would you like to open a new record?", vbYesNo, "Open SELA Records")
    If Answer = vbNo Then
    PWAnswer = Application.InputBox("Please enter the SELA Database password?")
    If PWAnswer <> Sheets("Security").Range("B2") Then
    Answer = MsgBox("The Password you have entered is incorrect.", vbOK, "ACCESS DENIED")
    Exit Sub
    Else
    Sheets("FIM Complaint Database").Visible = True
    Sheets("Review Existing Record").Select
    End If
    Else
    Sheets("FIM Complaint Database").Visible = True
    Sheets("New Record").Unprotect Password:=""
    Sheets("New Record").Select
    Range("C6") = "SELA"
    Sheets("New Record").Protect Password:=""
    End If
    End Sub

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by mdmackillop
    You can't change button titles on a standard messagebox.
    You can, but it is very unstable.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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