"KSH" <(E-Mail Removed)> wrote in message
news:FBCAACF8-185C-40BF-B2BA-(E-Mail Removed)
> Thanks but I was trying to avoid that also as to not list all the
> field names in case new ones are added. But unless I hear of
> something else that is what I will do.
>
> Thanks,
>
> Kerry
>
>
>> INSERT INTO ... SQL is more efficient than traversing a Recordset,
>> especially with large number of rows to be inserted.
>>
>> All you need to do is to list the Fields except for the ID Field,
>> something like:
>>
>> INSERT INTO TblSab900_history
>> ( {List of Fields except ID Field} )
>> SELECT {List of corresponding Fields except ID Field}
>> FROM TblSab900
>> WHERE {criteria if required}
If you're building the SQL statement in code, you could build the field
list on the fly by inspecting the table definition. The following rough
routine gives the idea, though it doesn't contain any error-handling or
cover all possible bases:
'----- start of code -----
Function fncFieldList( _
pstrTableName As String, _
Optional pblnExcludeAutonumber As Boolean) _
As String
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim strFieldList As String
Set db = Application.DBEngine.Workspaces(0).Databases(0)
Set tdf = db.TableDefs(pstrTableName)
For Each fld In tdf.Fields
If (fld.Attributes And dbAutoIncrField) Then
If Not pblnExcludeAutonumber Then
strFieldList = strFieldList & ", [" & fld.Name & "]"
End If
Else
strFieldList = strFieldList & ", [" & fld.Name & "]"
End If
Next fld
Set tdf = Nothing
Set db = Nothing
If Len(strFieldList) > 0 Then
fncFieldList = Mid$(strFieldList, 3)
End If
End Function
'----- end of code -----
In your case, you'd want to call the function with the option argument
pblnExcludeAutonumber set to True.
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)