CLEAR TEXT BOX AFTER USING COMMAND BUTTON PASSWORD

  • Thread starter Thread starter Jan Schweitzer via AccessMonster.com
  • Start date Start date
J

Jan Schweitzer via AccessMonster.com

I am new to this forum and to VB. No formal Access training, learned by
doing and reviewing this type of forum but I am stuck. My problem is very
elementary, I am sure. I have created a Password form with a text box and
command button using the script below for the Event Procedure for the
Command Button but I am not sure where and how to place the code to clear
the text box (textboxname.value=null). Is it to be included in this script
and if so where. Thank you in advance for the help.

Private Sub Open'formname'_Click()
If Me.'textboxname'= "password" Then
DoCmd.RunMacro "mcr"
Else
MsgBox "Incorrect Password.Please Try Again"

End If
End Sub
 
Depending on whether your macro needs the value in the textbox, put

Me.Textboxname=""

either before or after the macro runs.
 
Thank you for your quick response.

I need the text box cleared after the macro runs otherwise the incorrect
password message comes up. I added it as shown below and now I get a Run
Time Error '2467'- The expression you entered to an object that is closed
or doesn't exist.

Private Sub Open'formname'_Click()
If Me.'textboxname'= "password" Then
DoCmd.RunMacro "mcrforopenform"
Me.MktInfoPassword = ""
Else
MsgBox "Incorrect Password.Please Try Again"

End If
End Sub

I am sure this is basic Access and I appreciate the assistance.
 
Does your macro close the form that has the textbox "MktInfoPassword"? Or
perhaps that form no loger has the focus, so Me.MktInfoPassword won't work.
In that case, reference the form directly with:

forms!TheFormName.MktInfoPassword=""

instead of

me.MktInfoPassword=""
 
Mark - you are the man. Thank you so very much. I placed that script
before the DoCmd. statement and it runs like a charm.

Jan
 
Back
Top