Filter Error Message

GarageFlower

Registered User.
Local time
Today, 19:08
Joined
May 20, 2004
Messages
108
I have created forms for inputting into my database.

First of all a form opens with a choice of opening up another form displaying certain tables to input into.

On the startup form there is also a text box for the user to type in text and then using a command button filter the next form with what they have typed in.

Firstly when they dont enter anything into the text box but still press the command button this error box appears
"Syntax Error (missing operator) in query expression '[Last Name]='."
Then it just has an ok box

How do i get it come up with the message
"Please enter a Last Name before clicking run"
And then an OK

Secondly, once someone has entered the last name in the text box, pressed the command button, and the filtered form has opened and displayed the results, and then they close the results form and return to the original startup form. The text they entered in the text box is still there. Is there anyway of clearing it each time when they close the filtered form.

Many Thanks
 
Forms

One option is to disable the command button when the text box is empty.

In the On Current Event of the form put:

If Me.Textfield = "" Then
Me.Commandbutton.Enabled = False
Else
Me.Commandbutton.Enabled = True
End If

To clear the text field when the user returns to the form you
can put this in the On Activate Event of the form:

Me.Textfield = ""

Don't forget to subtitute 'textfield' and 'commandbutton' with
the proper names.

Hope this works.
 
Cheers mate the refresh thing worked well

I would still like an error message to appear if they click on run and there isnt anything in the text box....
 
Hi I followed your instructions for the on current code but it does not work

Open the form and error box comes up with

Compile Error

Method Or Data Member Not Found

Any ideas?

Or is there anyway i could change the error message that comes up when there is nothing entered in the text box and the command button is clicked?

Many Thanks
 
You could write an if statement in the on click event of the button to check to see if there is anything in the Last Name text box if not use a message box to say enter a last name.

If txtLastName = "" then
MsgBox "Endter a last name", vbExclamation
Else
Insert Code to open other form
End If

insert the name of your text box for txtLastName
 

Users who are viewing this thread

Back
Top Bottom