Stumped, MsgBox, empty fields

Blabolat

Registered User.
Local time
Today, 06:25
Joined
Feb 11, 2011
Messages
31
This probably elementary, but for the life of me I cannot figure out how, though, I have researched the net for an answer. I"m sure it's a pretty easy answer.

Have Main/Subform combo.

In the subform I have a field, [service_detail] that if left blank I want the user notified.

I created a If blank statement, but is ignored where ever I put it, form-after/before update, Field before/after update, etc.
seems to work on focus, but of course it always pops up if I leave the field or pop to another field.

Not sure where to put my if statement.

Help please?

thank you.
 
blank is not used in Access you need to check for null instead

If you post your code, someone may be able to help further

Usual place to put it is in the form before update event. Not much point in putting it in the control since it won't be triggered if the user doesn't go to that control.

Also, not much point putting it in the form afterupdate event - by then the record has been saved.

Have you tried modifying the table design to set the field Required property to yes?
 
If it's just a single field you could try something like ...

Code:
Private Sub Form_BeforeUpdate(Cancel as Integer)

  If Len(Me.yourControlName & vbNullString) = 0 Then ' If field has no characters in it

    MsgBox "Field 'yourControlName' should not be blank", vbInformation + vbOkOnly
    me.yourControlName.SetFocus
    Cancel = True

  Endif

End Sub

This would provide a prompt and automatically move the cursor to the offending field. If there was more than one field you could either create multiple If / Endif blocks, or be a little more creative.
 
blank is not used in Access you need to check for null instead

If you post your code, someone may be able to help further

Usual place to put it is in the form before update event. Not much point in putting it in the control since it won't be triggered if the user doesn't go to that control.

Also, not much point putting it in the form afterupdate event - by then the record has been saved.

Have you tried modifying the table design to set the field Required property to yes?

Thanks for the heads up, it's just how I termed it. Unwittingly I created a If isNull and object = "". probably late at night and I used blank and now I know some more.
thank you.
 
If it's just a single field you could try something like ...

Code:
Private Sub Form_BeforeUpdate(Cancel as Integer)

  If Len(Me.yourControlName & vbNullString) = 0 Then ' If field has no characters in it

    MsgBox "Field 'yourControlName' should not be blank", vbInformation + vbOkOnly
    me.yourControlName.SetFocus
    Cancel = True

  Endif

End Sub
This would provide a prompt and automatically move the cursor to the offending field. If there was more than one field you could either create multiple If / Endif blocks, or be a little more creative.

Thank you for your answer and reply. It's basically what I had tried earlier and with the same results. The form I speak of is a continuous form and only until I get to and through the following form does the message come back.

Now, it will come up with an error, since the focus is now on the following record.

I"ve tried that solution basically everywhere, form side, field side all to no avail.

I've gone into the table and made the field a required field, but it wasn't a very good solution and off hand I can't recall why, it was just a nasty message and I'm recalling that it may have done the same thing, as this solution you gave and I tried.

Any more ideas? thanks!
 
Oh, I set the field to be required in the Table design.

However, the error message, "You must enter a value..." pops up upon entering the form.. don't know.
 
If it's just a single field you could try something like ...

Code:
Private Sub Form_BeforeUpdate(Cancel as Integer)

  If Len(Me.yourControlName & vbNullString) = 0 Then ' If field has no characters in it

    MsgBox "Field 'yourControlName' should not be blank", vbInformation + vbOkOnly
    me.yourControlName.SetFocus
    Cancel = True

  Endif

End Sub
This would provide a prompt and automatically move the cursor to the offending field. If there was more than one field you could either create multiple If / Endif blocks, or be a little more creative.

As I suspected, does not work in a continuous subfrom mode.
Worked perfectly in 'single form' mode.

I"m getting to suspect, that the continuous mode was a after thought, and just threw in without the same benefits as the single form mode.

ON a similar note though,

Is there a method to have a another form, a contentious form with just a single row, very much like a split form mode that I can browse up and down and the main form is focused on what ever record row is selected?

or just selecting the record and have an event go to the record on the form.
I"m just not sure how to create the event, from a embedded sub form to another embedded form's on the same main form without calling up a new window.
I'll have to investigate that further.
I did try using the split from mode as a sub form and that too was a failure.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom