Cross-tab error

J

Jerry Crosby

I have a form based on a cross-tab query. The query has the potential
possibilities of 3 columns of data. But under some circumstances it may
only have 2 and when that happens, for that 3rd column, I get the "NAME#"
error (because the field I'm calling for doesn't surface in that particular
query).

I'd like to know how to code the form such that if the field doesn't exist
in the query, it just leaves the field blank.

I know I have mutilated this explanation, so feel free to ask a specific
question for clarification (and then return to read my response).

Thanks in advance.

Jerry
 
A

Alicia

In the OnOpen or OnCurrent event you could check the value in the box and if
it's "NAME#" then change it to "".
 
J

Jerry Crosby

Thanks, Alicia, but I couldn't get it to work. That may be because I didn't
know how to code it, but I think it's really because the field isn't
"#NAME?" as it appears. That's the error message, not the field value.
What's happening is that the form is calling for a field that is not in the
field list of the query. Therefore it errors.

Is there a way to code "if [fieldname] doesn't exist in the field list, then
do this..."?

Jerry
 
A

Alicia

Yes there is. You could do it with error handling. I'm not sure which event
you would put it in, maybe OnLoad or OnOpen or OnCurrent. You could start by
making sure that you are getting the number of the error like I did here:
===== just a sample =====================
Exit_Form_KeyPress:
Exit Sub
Err_Form_KeyPress:
Select Case Err.Number
Case 2105 'At start or end of records
MsgBox "No more records.", , "End"
Case Else
MsgBox Err.Description & vbCrLf & "Error: " & Err.Number
End Select
Resume Exit_Form_KeyPress
===== end sample =====================

but in yours you would just fill in the text box
with "" and make the code continue where it left off.
 
Top