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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

button to clear fields 1

Status
Not open for further replies.

smack317

IS-IT--Management
Apr 30, 2003
13
US
Could someone tell me how to clear the text boxes of a form using a command button?
 
Depending upon the type of control any of these different statements could work for you.

Me.Controlname = Null
or
Me.ControlName = ""
or
Me.ControlName = 0
or
Me.ControlName = False


Bob Scriver

Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
Hey Bob, I've seen your knowledgeable posts around the forum and thought you could clarify the advice of this post. I have a Query by Form that I'm using. I need the button as described by the original poster. With the QBF format, the textboxes are unbound. I'm a total novice when it comes to VB, but from the other posts that I looked at, the me.textboxname=Null command is a macro command. The comments I've read indicate that these types of commands can't be used with unbound sources. Therefore, I'm wondering what to do next.

I tried your advice above for just one of my textboxes, but it says that "Microsoft Access can't find the macro 'Title = Null'". In this case, Title is the name of my textbox.

Hopefully the above didn't seem critical. I just know that every person's database is different, so I had to explain the situation to you.

Thank you in advance for your help,
Mike Roha
 
You made me backup and retink my posting here. When you start to second guess yourself you feel really vulnerable. But, I created a form with four text boxes and entered data and the the following code cleared them when placed in a button. They were unbound controls:
Me.Text0 = Null
Me.Text2 = Null
Me.Text4 = Null
Me.Text6 = Null

Now we really should be using a slightly different syntax so that ACCESS doesn't get confused.
Me![Text0] = Null
Me![Text2] = Null
Me![Text4] = Null
Me![Text6] = Null

Now from your post ACCESS is looking for a Macro named Me with a Macro Name called your control name. I think because of the syntax that I posted it may be looking at the statement as a macro call rather than a control name.
Sometimes we get lazy and type me. and then access gives us the dropdown box of controls on the form. We actually use the syntax that I provided Me![ControlName] and if you make the change I think it will work for you.

Post back with what you find and any further questions.

Bob Scriver
Want the best answers? See FAQ181-2886
Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
Thanks for your prompt reply Bob. I must be a bigger novice than I thought. I've tried putting that statement (modified for my particular text box) in the OnClick block under the button properties. That didn't give me the error, but it didn't work either. I just put the code straight into the block, I didn't use the expression, code, or macro builders.

I am unfamiliar with the Visual Basic syntax, but I tried putting my statement into it. I included it below. It could be that I'm including it in the wrong place, or maybe I need to build an expression?

Private Sub Command24_Click()
On Error GoTo Err_Command24_Click

Me![Title] = Null

DoCmd.Quit

Exit_Command24_Click:
Exit Sub

Err_Command24_Click:
MsgBox Err.Description
Resume Exit_Command24_Click

End Sub

Private Sub Command26_Click()

End Sub

Thanks again for your help. There's no hurry on the reply, I'm going to be out of town until Wednesday.

Mike Roha
 
Okay, I see from your posts that you were typing me.textcontrolname = null directly into the OnClick box. Is that what you did? If so then that is why it was looking for a macro. Your choices there are either [Event Procedure] or a macro name. Since you didn't have a macro name called 'Title = Null' so you got the no macro found error.

The code you used is just fine except the red code should be removed. The only thing that I see is that you have two command button OnClick procedures here. Command24 and Command26. You put the code in 24 and 26 is left blank. Make sure that you are putting the code in the button that you are clicking.

Private Sub Command24_Click()
On Error GoTo Err_Command24_Click
Me![Title] = Null
DoCmd.Quit
Exit_Command24_Click:
Exit Sub
Err_Command24_Click:
MsgBox Err.Description
Resume Exit_Command24_Click
End Sub

Private Sub Command26_Click()

End Sub


Post back at your convenice your results.

Bob Scriver
Want the best answers? See FAQ181-2886
Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
That worked great! Thanks a lot for your help Bob!

I should have paid more attention, I've had some slight programming experience. I figured that when I opened a new event procedure that it would include only the syntax for the button I was working on. I may have selected the other button or something. You live and you learn I guess. I'll be sure to remember this little tidbit, as I need it for a couple of different databases. I was able to pick up and use the setfocus command as well for added functionality.

Again, I sincerely appreciate your help Bob!

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top