Suppressing run-time error message

G

Guest

Basically I am trying to force the user to enter information into a field
after a combo box has been changed. On a form I have a combo box which lists
document files.

On the afterupdate event for the combo I have:

DoCmd.GoToControl "Act_ProcNF2"

In the "Gotfocus" event for "Act_ProcNF2" I have:

Me.Act_ProcNF2 = ""

This second line produced a run-time error (cannot be a zero-length string).
How can I suppress this? I want the "N/A" to be deleted but this doesn't
happen.

How can I solve this or is there an easier way?
 
S

Stefan Hoffmann

hi,
Basically I am trying to force the user to enter information into a field
after a combo box has been changed. On a form I have a combo box which lists
document files.

On the afterupdate event for the combo I have:

DoCmd.GoToControl "Act_ProcNF2"

In the "Gotfocus" event for "Act_ProcNF2" I have:

Me.Act_ProcNF2 = ""

This second line produced a run-time error (cannot be a zero-length string).
How can I suppress this? I want the "N/A" to be deleted but this doesn't
happen.

How can I solve this or is there an easier way?
First of all, the gotfocus is not necessary. Just place the

Me.Act_ProcNF2 = ""
DoCmd.GoToControl "Act_ProcNF2"

in your after update event.

If your field allows Null use

Me.Act_ProcNF2 = Null
DoCmd.GoToControl "Act_ProcNF2"

instead. Otherwise you have to assign a value indicating that no input
was made.


mfG
--> stefan <--
 
G

Guest

I have tried your code but the cursor stays in the combo box and the field
doesn't change. I still get the run-time error.

I have also switched the two lines. The cursor goes into the field but "N/A"
doesn't get deleted and I still get the error

?????
 
S

Stefan Hoffmann

hi,
I have tried your code but the cursor stays in the combo box and the field
doesn't change. I still get the run-time error.
Does your field allow Null or empty values?

Me.Act_ProcNF2 = ""

should point to your control on the form, not to the field. If
Act_ProcNF2 is a field, use the control instead:

txtActProcNF2.Value = Null



mfG
--> stefan <--
 
G

Guest

I had the impression that a field is a control. Or not? "Act_ProcNF2" is a
text box that requires it not to be null (if that helps!)
 
S

Stefan Hoffmann

hi,
I had the impression that a field is a control. Or not? "Act_ProcNF2" is a
text box that requires it not to be null (if that helps!)
Not really. You have to distinguish between fields and controls. But if
your TextBox requiers not to be null and the error messages says "cannot
be a zero-length string" then you can't neither set it to Null nor "".
You have to assign a non-zero length string indicating no input.


mfG
--> stefan <--
 
G

Guest

You have to assign a non-zero length string indicating no input.

Like " " (with a space?) rather than "" or do I not understand?
 
G

Guest

I am beginning to struggle over this, I am getting confused and I can't work
out in my head what to do.

The field that is required has its "required" property set to "yes" and the
default value is "N/A". I was intending to delete the "N/A" in the "after
update" event in the combo so it would throw up an error to make sure that
the field is updated (the form is continuous). Logical to me but I am getting
this "zero-length string" error.

If I set the field to allow a zero-length string then it can effectively
allow nothing to be entered in the field even after the combo has been
updated which is not what I want.
 
G

Guest

I could set the field "required" property to "no" but I don't know how much
easier it would be.
 
S

Stefan Hoffmann

hi,
I am beginning to struggle over this, I am getting confused and I can't work
out in my head what to do.
Time for a coffee break :)
The field that is required has its "required" property set to "yes" and the
default value is "N/A". I was intending to delete the "N/A" in the "after
update" event in the combo so it would throw up an error to make sure that
the field is updated (the form is continuous). Logical to me but I am getting
this "zero-length string" error.
Use the after change event of your combo box.


mfG
--> stefan <--
 
J

John W. Vinson

This second line produced a run-time error (cannot be a zero-length string).
How can I suppress this? I want the "N/A" to be deleted but this doesn't
happen.

You haven't said what the "N/A" is, where it comes from, or from where you
want it deleted.

John W. Vinson [MVP]
 
D

Douglas J. Steele

Why on earth would you have a default value if you're just going to throw it
away? The purpose of a default value is to set what value the field will
have if a value isn't provided.
 
G

Guest

Exactly.

The field may not always be applicable depending on other information that
is entered into other fields. The combo box contains a list of documents. If
a document is not appropriate for that record then the following field has to
be "N/A" as well.

That is why I set the "required" property to "yes".
 
G

Guest

I read my posts and think "that didn't make sense" !

The field that is required has its "required" property set to "yes" and the
default value is "N/A". I was intending to delete the "N/A" in the "after
update" event in the combo so it would throw up an error to make sure that
the field is updated (the form is continuous). Logical to me but I am getting
this "zero-length string" error.

If I set the field to allow a zero-length string then it can effectively
allow nothing to be entered in the field even after the combo has been
updated which is not what I want.

Am I making this more complicated than necessary?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top