Clear Form

  • Thread starter JezLisle via AccessMonster.com
  • Start date
J

JezLisle via AccessMonster.com

I am using this code at the end of my routine that once all data has been
updated in the table it then clears all values from the TextBox's or Combo's
on the form.

My problem is that I keep getting this error message on the following code
and dont know why or how to get around it

Me.PersonalID.Value = ""
Me.txtForename.Value = ""
Me.txtSurname.Value = ""
Me.txtAddress1.Value = ""

Error: "You tried to assign the NULL value to a variable that is not a
Variant data type"

What would this appear for, as all I was trying to do is clear any values in
TextBox's or Combo's on the form?
 
A

Allen Browne

If this form is bound to a table or query, perhaps you could just move it to
a new record with:
If Me.Dirty Then Me.Dirty = False
RunCommand acCmdRecordsGotoNew

If you don't want to save the record, perhaps you could undo the current
edits:
Me.Undo

If it is unbound, it would probably be better to assign Null rather than a
zero-length string, e.g.:
Me.PersonalID = Null

If you are still stuck, comment out all lines but one, and see if the error
occurs. Repeat with different lines in, until you pin down the problem one.
 
J

JezLisle via AccessMonster.com

Thanks,

I have a form which is bound apart from the PatientNo which I input via an
input box.

does that make a difference?

The Me.TextBox = "" seems to work fine, it is just the PatientNo TextBox
which is unbound, how can I clear this to then input a new number?


Allen said:
If this form is bound to a table or query, perhaps you could just move it to
a new record with:
If Me.Dirty Then Me.Dirty = False
RunCommand acCmdRecordsGotoNew

If you don't want to save the record, perhaps you could undo the current
edits:
Me.Undo

If it is unbound, it would probably be better to assign Null rather than a
zero-length string, e.g.:
Me.PersonalID = Null

If you are still stuck, comment out all lines but one, and see if the error
occurs. Repeat with different lines in, until you pin down the problem one.
I am using this code at the end of my routine that once all data has been
updated in the table it then clears all values from the TextBox's or
[quoted text clipped - 15 lines]
in
TextBox's or Combo's on the form?
 
A

Allen Browne

After the suggested RunCommand line, add:
Me.PersonalID = Null

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

JezLisle via AccessMonster.com said:
Thanks,

I have a form which is bound apart from the PatientNo which I input via an
input box.

does that make a difference?

The Me.TextBox = "" seems to work fine, it is just the PatientNo TextBox
which is unbound, how can I clear this to then input a new number?


Allen said:
If this form is bound to a table or query, perhaps you could just move it
to
a new record with:
If Me.Dirty Then Me.Dirty = False
RunCommand acCmdRecordsGotoNew

If you don't want to save the record, perhaps you could undo the current
edits:
Me.Undo

If it is unbound, it would probably be better to assign Null rather than a
zero-length string, e.g.:
Me.PersonalID = Null

If you are still stuck, comment out all lines but one, and see if the
error
occurs. Repeat with different lines in, until you pin down the problem
one.
I am using this code at the end of my routine that once all data has been
updated in the table it then clears all values from the TextBox's or
[quoted text clipped - 15 lines]
in
TextBox's or Combo's on the form?
 

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

Top