wrong field names

M

merry_fay

Hi,

To import a table, I'm forming a link to excel, then running an append query
in code on my form to put the information in the desired table with
additional bits.
I've got the 'On Error GoTo' bit in my code, but when a column header is
wrong in the excel spreadsheet, instead of going to my error code, it asks me
for the parameter value of the field name that should have been in the
spreadsheet.

Is there any way I can make this become an error so my error code kicks in?
I'm already using 'DoCmd.SetWarnings False'

Thanks
merry_fay
 
D

Douglas J. Steele

Unfortunately, there's no way to intercept the prompt that I'm aware of.

You'll have to add code to check that everything's okay before you run the
append query.
 
M

merry_fay

I've been trying to find a way of checking the field names in the link table
(or any table for that matter), but can't find the right code. I'm trying to
do something like:

if field name "Company" can't be found then .... else ...

but it's the field name "Company" bit I can't get.

Is there some code for looking at field names?

Thanks
merry_fay
 
D

Douglas J. Steele

See whether this helps:

Function FieldExists( _
TableName As String, _
FieldName As String _
) As Boolean
' Returns True if the field exists in the table.
' Returns False otherwise.

On Error Resume Next

Dim tdfCurr As DAO.TableDef
Dim strField As String

Set tdfCurr = CurrentDb.TableDefs(TableName)
If Err.Number = 0 Then
strField = tdfCurr.Fields(FieldName)
FieldExists = (Err.Number = 0)
End If
Set tdfCurr = Nothing

End Function
 

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