Run time error problem

  • Thread starter Thread starter Philip Martin
  • Start date Start date
P

Philip Martin

Hope someone can help on this. Having just finished the bulk of a new data
base, I'm just doing some tidying up and putting in some error checking and
wrong data entry loops. The following bit of code is driving me nuts! The
same bit of code, in the same module just before it works fine, all be it
looking at a different field within the table and it being numeric rather
than text. But every time I run this section I get the error code 2001 and
the message 'You cancelled the previous operation' ????

I have even commented out all the preceding code so only this section runs,
but still the same problem. I have also double checked the spelling of all
table references and they are exact.

If IsNull(Text0) Then
temp2 = "b"
GoTo Jump2

ElseIf IsNull(DLookup("[Surname]", "CustName", "[Surname]=" &
Forms!FindEditCusDeFrmt!Text0)) Then
temp2 = "b"
Else
temp2 = "a"

End If

Any pointers would be most welcome.

TIA

Philip Martin.
 
The error can indicate that one of the DLookup() arguments is malformed. If
Surname is a Text field (not a Number field), you need quote marks as
delimiters in the 3rd argument:

DLookup("[Surname]", "CustName", "[Surname]=""" &
Forms!FindEditCusDeFrmt!Text0 & """")

For an explanation of that see:
http://allenbrowne.com/casu-07.html

If that is not the issue, what event are you using for this code? Any test
for Null really needs to happen in the BeforeUpdate event of the *form*, not
the control. The control''s events won't fire if the user never visits the
control.
 
Allen Browne said:
The error can indicate that one of the DLookup() arguments is malformed. If
Surname is a Text field (not a Number field), you need quote marks as
delimiters in the 3rd argument:

DLookup("[Surname]", "CustName", "[Surname]=""" &
Forms!FindEditCusDeFrmt!Text0 & """")

For an explanation of that see:
http://allenbrowne.com/casu-07.html

If that is not the issue, what event are you using for this code? Any test
for Null really needs to happen in the BeforeUpdate event of the *form*, not
the control. The control''s events won't fire if the user never visits the
control.

Cheers Allen, that worked a treat:o)

The Null and DLookup test is checking for valid data being input into a form
that is then used to seed a query. Just trying to make the error handling
easier for the end users.

One further question if I may.

The above code works well and will cope with the input of a wrong name or
even numeric input. I have some code prior to this to detect NO input. But I
also have a like of similar code that checks a numeric field. This works
fine with NO input or the wrong (not valid) number, but has the same problem
if Text is mistakenly entered into the field. Is it possible to trap this
error whilst still referring to a numeric field in the table being looked
up.

Many thanks for your help.

Philip Martin.
 
If you enter text into a control that is bound to a Number field, the form's
Error event will be triggered before it can run your code.

Use the form's Error event, and handle DataErr 2113.

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

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

Philip Martin said:
Allen Browne said:
The error can indicate that one of the DLookup() arguments is malformed. If
Surname is a Text field (not a Number field), you need quote marks as
delimiters in the 3rd argument:

DLookup("[Surname]", "CustName", "[Surname]=""" &
Forms!FindEditCusDeFrmt!Text0 & """")

For an explanation of that see:
http://allenbrowne.com/casu-07.html

If that is not the issue, what event are you using for this code? Any test
for Null really needs to happen in the BeforeUpdate event of the *form*, not
the control. The control''s events won't fire if the user never visits the
control.

Cheers Allen, that worked a treat:o)

The Null and DLookup test is checking for valid data being input into a form
that is then used to seed a query. Just trying to make the error handling
easier for the end users.

One further question if I may.

The above code works well and will cope with the input of a wrong name or
even numeric input. I have some code prior to this to detect NO input. But I
also have a like of similar code that checks a numeric field. This works
fine with NO input or the wrong (not valid) number, but has the same problem
if Text is mistakenly entered into the field. Is it possible to trap this
error whilst still referring to a numeric field in the table being looked
up.

Many thanks for your help.

Philip Martin.
 
Allen Browne said:
If you enter text into a control that is bound to a Number field, the form's
Error event will be triggered before it can run your code.

Use the form's Error event, and handle DataErr 2113.
That makes sense, obvious too, when you think about it;o)

Thanks again for the help.

Philip Martin.
 
Back
Top