Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SET PASSWORD FOR ACTION BUTTON

Status
Not open for further replies.

h2mhd

Programmer
Feb 20, 2008
40
CA
HI

i have a form invoice that have a modify button that let the user to modify the content of the invoice.

I want to set a password for this button so i created a form security that contains a input field text, where i enter a password. Once the password is entered i click on a button that launch the password check unto the database.

once the checkup is done i just want to return to my invoice form and validate if the password is ok or not, if ok we continue with unlocking all the fields if not simply show a message of error.

but i dont know how to do that?? can someone help me please with that

thanks a lot
 
You could use something like the following in the on click event of a button, with your own password where "yourpassword" is and your own object names for object1 and object2 and so on.



Dim inpbox As String
Dim answer As Integer

answer = MsgBox("Are you sure you wish to modify this record?", vbYesNo + vbExclamation + vbDefaultButton2, "GMIL LRT Database Record Delete Confirmation")
If answer = vbYes Then
inpbox = InputBoxDK("Please enter the correct password to enable modification of this record.")

If inpbox = "yourpassword" Then

me.object1.enabled = true
me.object2.enabled = true
else

MsgBox "Wrong password!", vbOKOnly
me.object1.enabled = false
me.object2.enabled = false

end if
 
Ignore the "GMIL LRT Database Record Delete Confirmation" that's what I was using this for in my database. Replace that with your own title.
 
I removed my title and replaced the InputBoxDK with InputBox (InputBoxDK() requires Daniel Klanns masked input box module
Dim inpbox As String
Dim answer As Integer

answer = MsgBox("Are you sure you wish to modify this record?", vbYesNo + vbExclamation + vbDefaultButton2, "Modify Record password confirmation.")
If answer = vbYes Then
inpbox = InputBox("Please enter the correct password to enable modification of this record.")

If inpbox = "yourpassword" Then

me.object1.enabled = true
me.object2.enabled = true
else

MsgBox "Wrong password!", vbOKOnly
me.object1.enabled = false
me.object2.enabled = false

end if
 
You can build a much better reuseable input box on your own with out the API workaround. Provides a whole lot more flexibility. I would never use an input box in an access application for any reason. You are very limited in what you can do, and to add data verification you need another work around. Here is a better way that is more flexible and easier.

build a Input box form.
Need
text box for the input
text box for the message
Command button OK
Command button Cancel

Format it to fit your needs
code on form:
Code:
Private Sub cmdCancel_Click()
  DoCmd.Close acForm, Me.Name
End Sub
Private Sub cmdOK_Click()
  Me.Visible = False
End Sub
Private Sub Form_Load()
  If Not IsNull(Me.OpenArgs) Then
    Me.lblMessage.Caption = Split(Me.OpenArgs, ";")(0)
    Me.Caption = Split(Me.OpenArgs, ";")(1)
    Me.txtBxInput = Split(Me.OpenArgs, ";")(2)
  Else
    MsgBox "Need to open from function myInputBox"
  End If
End Sub

Build a function in a standar module
Code:
Public Function myInputBox(prompt As String, Optional Title As String = "", Optional Default As Variant = "") As Variant
   Dim strArgs As String
   Dim frm As Access.Form
   strArgs = prompt & ";" & Title & ";" & Default
   DoCmd.OpenForm "frmInputBox", , , , , acDialog, strArgs
   If CurrentProject.AllForms("frmInputBox").IsLoaded Then
     Set frm = Forms("frmInputBox")
     myInputBox = frm.txtBxInput
     DoCmd.Close acForm, frm.Name
   End If
End Function

now to use it. In this example returning the value back to a textbox on another form and setting the input box default value to the value in the textbox
The caption on the Input box will be "Student ID" the message will be "Enter Student ID" and the default will be the value in the calling forms txtbxone.
Code:
Private Sub cmdMyInput_Click()
  Me.txtBxOne = myInputBox("Enter StudentID", "Student ID", Me.txtBxOne)
End Sub

I did not set this up to allow you to pass a format for the textbox. So if you want to use this for other things then make a new function and new input box form.
Call the form
frmPasswordInputBox

then call the function myPasswordInputBox
Have that function call frmPasswordInputBox instead of frmInputBox

That would be a little easier then having to pass a format string in to the input box. Although this could be done.

The way this works is that the function calls the input box form in dialog mode. Code execution halts in the calling code until either the input form is hidden (OK) or close (Cancel). Code execution then returns to the myInputBox function. If the form is hidden, then it reads the value and closes the inputbox. Then returns the value to the original code that called the function.

This concept is by far the best way in general to return values from dialog forms.

The only limitation on this is the size of the inputbox and size of the message. I made my form big enough to handle a large message. It is a transparent textbox so you can not really tell. However, If I wanted I could simply write some code to size the message textbox and the form to match.
 
Thanks a lot for your response that very appreciated!

and it works!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top