Appending

T

TMSpurr

Trying to append data to a master data table. I can copy
the fields in to the master table and that works fine,
field for field and row for row, no problem. However, I
am getting a validation rule violation when trying to
append the data. I have no validation rules set up and
can't find the issue. I've check data types and sizes,
and the fact that I can paste the data in okay has got me
puzzled. Please Help! Hot project and I'm stuck. Thanks
in advance!
 
T

TMSpurr

Please help. I am missing something here. I create a
make table, and then try to append the exact same data to
the new table and get the validation rule violation.
Other than creating a rule, why else would I get this
message? I hope someone helps. This is a huge project,
and a fairly large table, but a very simple append, and I
don't know what could be the problem. I would really
appreciate some expertise. Thanks.
 
G

Gary Walter

TMSpurr said:
Trying to append data to a master data table. I can copy
the fields in to the master table and that works fine,
field for field and row for row, no problem. However, I
am getting a validation rule violation when trying to
append the data. I have no validation rules set up and
can't find the issue. I've check data types and sizes,
and the fact that I can paste the data in okay has got me
puzzled. Please Help! Hot project and I'm stuck. Thanks
in advance!

Hi TM,

Would you mind starting a new module,
copy and paste the following code into
the module, save the module (as say "modUtil"),
make sure you have reference to DAO library,
compile it to verify okay (watch word wrap),
then in Immediate window
run the function on your master data table.

?fListTableFields("nameofyourtable")

Then copy and paste results back here?

Or...turn your append query into a make table
query, run it, then run this function on the table
you just made, then compare the two results.

I would look specifically at these 2 properties
for reasons you are getting this error:

Required = ?
AllowZeroLength = ?

Thanks,

Gary Walter

'***start code ****
Option Explicit
Public Function FieldType(intType As Integer) As String
'from post by Dan Artuso
Select Case intType
Case dbBoolean
FieldType = "dbBoolean"
Case dbByte
FieldType = "dbByte"
Case dbInteger
FieldType = "dbInteger"
Case dbLong
FieldType = "dbLong"
Case dbCurrency
FieldType = "dbCurrency"
Case dbSingle
FieldType = "dbSingle"
Case dbDouble
FieldType = "dbDouble"
Case dbDate
FieldType = "dbDate"
Case dbText
FieldType = "dbText"
Case dbLongBinary
FieldType = "dbLongBinary"
Case dbMemo
FieldType = "dbMemo"
Case dbGUID
FieldType = "dbGUID"
End Select

End Function

Public Function FieldOutput(fldTemp As DAO.Field) As Variant
' adapted from Access Help

Dim prpLoop As DAO.Property
Dim strProp As String

' Enumerate Properties collection of passed Field
' object.
For Each prpLoop In fldTemp.Properties
' Some properties are invalid in certain
' contexts (the Value property in the Fields
' collection of a TableDef for example). Any
' attempt to use an invalid property will
' trigger an error.
On Error Resume Next
strProp = strProp & prpLoop.Name & " = " & _
prpLoop.Value & vbCrLf
On Error GoTo 0
Next prpLoop

FieldOutput = strProp

End Function

Public Function fListTableFields(pT1 As String) As Boolean
On Error GoTo Err_fListTableFields
Dim db As DAO.Database
Dim tdf1 As DAO.TableDef
Dim fld As DAO.Field
Dim fld1 As DAO.Field
Dim idx As DAO.Index
Dim strName1 As String
Dim strType1 As String
Dim varProp1 As Variant
Dim i As Integer

Set db = CurrentDb
Set tdf1 = db.TableDefs(pT1)

Debug.Print "Table: " & pT1

For i = 0 To tdf1.Fields.Count - 1
Debug.Print "----------------------------"
Set fld1 = tdf1.Fields(i)
varProp1 = FieldOutput(fld1)
strName1 = fld1.Name
strType1 = FieldType(tdf1.Fields(i).Type)
If strType1 = "dbText" Then
strType1 = strType1 _
& " (" & tdf1.Fields(i).Size & ")"
End If
'is it a primary key?
For Each idx In tdf1.Indexes
If idx.Primary Then
' Found a Primary Key
For Each fld In idx.Fields
If fld.Name = strName1 Then
strType1 = strType1 & " (pk)"
Exit For
End If
Next fld
Exit For
End If
Next idx

Debug.Print "Field: " & strName1 & vbCrLf _
& "Field Type: " & strType1 _
& vbCrLf & varProp1

Next i

Debug.Print "----------------------------"

db.Close

fListTableFields = True

Exit_fListTableFields:
Set fld1 = Nothing
Set tdf1 = Nothing
Set db = Nothing
Exit Function

Err_fListTableFields:
MsgBox Err.Description
Resume Exit_fListTableFields
End Function
'**** end code ****
 
G

Gary Walter

TMSpurr said:
Trying to append data to a master data table. I can copy
the fields in to the master table and that works fine,
field for field and row for row, no problem. However, I
am getting a validation rule violation when trying to
append the data. I have no validation rules set up and
can't find the issue. I've check data types and sizes,
and the fact that I can paste the data in okay has got me
puzzled. Please Help! Hot project and I'm stuck. Thanks
in advance!

Hi TM,

While you are "at it," add the following code to
your module and run it also against your master table
in the Immediate window.

?GetIndexes("nameofyourtable")


'***start code***
Function GetIndexes(pstrTableName As String) As Boolean
'adapted from NEAT CD
' Prints indexes in Immediate Window
On Error GoTo Err_GetIndexes
Dim DB As DAO.Database
Dim tdf As DAO.TableDef
Dim indx As DAO.Index
Dim i As Integer
Set DB = CurrentDb
Set tdf = DB.TableDefs(pstrTableName)
Debug.Print "TableName: " & pstrTableName
Debug.Print "Index Count: " & tdf.Indexes.Count
For i = 0 To tdf.Indexes.Count - 1
Set indx = tdf.Indexes(i)
Debug.Print vbCrLf & "Index Name: " & indx.Name
Debug.Print " Primary: " & indx.Primary
Debug.Print " Foreign: " & indx.Foreign
Debug.Print " Clustered: " & indx.Clustered
Debug.Print " Fields: " & indx.Fields
Debug.Print " Required: " & indx.Required
Debug.Print " Unique: " & indx.Unique
Debug.Print " Ignore Nulls: " & indx.IgnoreNulls

Next i
DB.Close
GetIndexes = True

Exit_GetIndexes:
Set tdf = Nothing
Set DB = Nothing
Exit Function
Err_GetIndexes:
GetIndexes = False
If Err = 3265 Then
MsgBox "The table " & pstrTableName & " does not exist."
Resume Exit_GetIndexes
Else
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume Exit_GetIndexes
End If
End Function
'***end code****

Thanks,

Gary Walter
 
G

Guest

Gary,

THANKS!! It was the "Allow Null Values" that were set to
NO upon creation of the table. Corrected that and the
query appends correctly now. Thanks for helping, and I'm
moving again. I REALLY APPRECIATE your help!

TM
 

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