what's wrong in code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
following code is in formX's OnCurrent event procedure and it always breaks on DoCmd.Clos

If IsNull(textBoxS) The
DoCmd.Close acForm, "formX
Els
..
End I

Any clues

alekm
 
Try this!

If IsNull(Me.textBoxS) Then
DoCmd.Close acForm, "formX"
Else
...
End If

You need, not allways, to refere to which control on which form/report and
in this case I asume you have the code in a module of the same form that you
wish to close!?

There could, offcourse, be another problem here. Does control with name
"textBoxS" exist on the form/report?

// Niklas
 
txtBoxS exists that's ok
I tried Me.txtBoxS. Nothing's changed
Yes,I have the code in a module of the same form that I
wish to close. Might that be problem?

alekm
 
Ok!

In which event do you have the code?

You could try creating a command button (cmdCloseForm) and put folowing code
in Click_Event for the commandbutton:

If IsNull(textBoxS) Then
DoCmd.Close
Else
...
End If

Or maby your problem is that Me.textBoxS isn´t null. Try this:

If IsNull(Me.textBoxS) Or Me.textBoxS = "" Then
DoCmd.Close
Else
...
End If

DoCmd.Close will close the form or report that the code goes in! So you
don´t need to specifye which form/report as long as it´s the same
form/report.

// Niklas



// Niklas
 
Well have you tryed the code below in a commandbuttons click_event yet? If
so what happened?

You say that the code breake at DoCmd.Close. How?
Do you get any error messages?
If so which number?

Create a new commandbutton and write or past/copy this code (below) in that
commandbutton´s click_event.

If IsNull(Me.textBoxS) Or Me.textBoxS = "" Then
DoCmd.Close
End If


// Niklas
 
I get following error when DoCmd.Close is called from form's OnCurrent even

Run-time error 258
This action can't be carried out while processing a form or report even

I guess I can't execute DoCmd.Close from form's OnCurrent event at all
What is the event that is next one after OnCurrent event
Maybe I can use that one

alekm
 
Yes, that´s quit obvoius. Sorry that I didn´t spot that one earlyer. Close
the form you are in from the same form´s OnCurrent_Event don´t work!

I would use the texbox´s [textBoxS] LostFocus event since it´s acually after
editing just that control you need to make the validation. Or do you want to
close the form everywhere if textBoxS = Null?

I wouldn´t because what happens if you try to open the form and you make the
validation on the form´s Open_Event or Load_Event. ??? This will cause
either a runtime error or close the form every time you try to open it.

The best way is to make sure that you run the validation when textBoxS loses
focus.

// Niklas
 
We are back at square one
I want to close form immediately if underlaying sql fills textBoxS with null but I dont want to introduce additional sq
before opening the form to just check whether textBoxS would be null or not
So lost focus event is not the clue

In other words: how to prevent form from opening if it's textBoxS would be null after opening, not introducing additional sq
besides form's source sq

alekm
 
Well, to be able to check textBoxS you have to open the form first. The
controls on the form doesn´t have any value what so ever until the form have
been loaded.

So you have to check the value which should have been loaded into textBoxS
BEFORE you try to open the form and then DoCmd.Cancel on the event
DoCmd.Open (form).

One way is to use DLookUp function if you don´t want to use SQL. But to be
able to help you out with this one I need to know the name of the table or
query which is the recordsource to the form you try to open. I also need to
know the name of the field which should have been the controlsource for
textBoxS. And I need to know the evaluation you want to make.

Do you try to open the form from a cmd in another form or what?

// Niklas


alekm said:
We are back at square one!
I want to close form immediately if underlaying sql fills textBoxS with
null but I dont want to introduce additional sql
before opening the form to just check whether textBoxS would be null or not.
So lost focus event is not the clue.

In other words: how to prevent form from opening if it's textBoxS would be
null after opening, not introducing additional sql
 
Back
Top