Discussion Locked

Access2000 Field names argument

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have a dateabse that imports spreadsheets submitted by many people and manipulates the data. But before the queries are let loose on the imported table I need to ensure the field names are absolutly correct to avoid parameter errors and forced changes to the queries.
Does anyone know any code or the correct arguments to check the field names so I can then get the code to exit before the queries are started?

4 replies

by andrew

Here's a code snippet that walks all the fields in an ADO recordset, checking each field name:

Dim oCon as ADODB.Connection
Dim oRs as ADODB.Recordset

Set oCon = New ADOSB.Connection
oCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Password="";Data Source=Z:\dbname.mdb;"

Set oRs = New ADODB.Recordset
oRs.Open "SELECT top 1 * FROM TableName", oCon

For lCol = 0 To oRs.Fields.Count - 1
If oRs.Fields(lCol).Name <> sFieldName(lCol) Then
'problem with field!
End If
Next 'lCol

This code assumes you have a prepopulated array of proper field names in sFieldName.

Hope this helps.

by paul.winterburn

I could see where the code was going but could not get it too work.
My experience of coding made it difficult to attack the errors, for instance my set up would not allow 'oConb.open' to work.

This discussion is closed to new replies.