Hi all,
i want to ask when importing data from a text file ,if this data is appended to a table or just inserted?
What is my problem?
I have 4 txt delimited files which update every week. So once a week i have to import the data from the txt files in 4 different tables in my database.
These 4 tables are related to each other with one to many relationship.
To be more specific,Table 1 is Customers which is related to the other 3 tables with one to many relation.I have deactivated the relationship integrity in all these relations.
When i try to import the txt files ,the data is not appended an an error occurs which says how many rows deleted,how many rows lost due to primary key violation etc...,although i have checked that all data types are ok.When the table is empty,all data are inserted in tha table without problems,but the problem occurs the second time that i will import data in the same table.
I dont want to delete the data already in these tables before attempting to import updated data from txt files because i want to keep old data (old customers who have stopped being active anymore) which maybe dont exist in new updated txt files each week.
Please,can someone help me with this?
Below,i have the code which lets me browse and pick a txt file from the disk and imports it in the table.(2 subs)
Private Sub browseaf_Click()
On Error GoTo Err_browseaf_Click
'Declare a variable as a FileDialog object.
Dim fd As FileDialog
Dim vrtSelectedItem As Variant
'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)
'Reference the FileDialog object.
With fd
'Allow the user to select only one file.
.AllowMultiSelect = False
' Show method to display the File Picker dialog box and return the user's action.
'The user pressed the action button.
If .Show = -1 Then
'Step through each string in the FileDialogSelectedItems collection.
Forms![browse_form]![txtfilenameaf].Enabled = True
Forms![browse_form]![txtfilenameaf].SetFocus
For Each vrtSelectedItem In .SelectedItems
'Lstbox.RowSourceType = "value List"
txtfilenameaf.Text = vrtSelectedItem
Next vrtSelectedItem
'The user pressed Cancel.
Else
Set fd = Nothing
Exit Sub
End If
End With
'DoCmd.SetWarnings False
MsgBox "You selected: " & txtfilenameaf.Text
Af1
' Set form controls
'Forms![browse_form]![txtfilenameaf].Enabled = True
'Forms![browse_form]![txtfilenameaf].SetFocus
Forms![browse_form]![browseaf].Enabled = True
'Set the object variable to Nothing.
Set fd = Nothing
Exit_browseaf_Click:
Exit Sub
Err_browseaf_Click:
MsgBox Err.Description
Resume Exit_browseaf_Click
End Sub
--------------------------------------------------------------------------
Public Sub Af1()
On Error GoTo af1_Err
DoCmd.SetWarnings False
DoCmd.TransferText acImportDelim, "Af1", "Af1", txtfilenameaf.Text, False, ""
af1_Exit:
Exit Sub
af1_Err:
DoCmd.SetWarnings True
MsgBox Error$
Resume af1_Exit
End Sub
i want to ask when importing data from a text file ,if this data is appended to a table or just inserted?
What is my problem?
I have 4 txt delimited files which update every week. So once a week i have to import the data from the txt files in 4 different tables in my database.
These 4 tables are related to each other with one to many relationship.
To be more specific,Table 1 is Customers which is related to the other 3 tables with one to many relation.I have deactivated the relationship integrity in all these relations.
When i try to import the txt files ,the data is not appended an an error occurs which says how many rows deleted,how many rows lost due to primary key violation etc...,although i have checked that all data types are ok.When the table is empty,all data are inserted in tha table without problems,but the problem occurs the second time that i will import data in the same table.
I dont want to delete the data already in these tables before attempting to import updated data from txt files because i want to keep old data (old customers who have stopped being active anymore) which maybe dont exist in new updated txt files each week.
Please,can someone help me with this?
Below,i have the code which lets me browse and pick a txt file from the disk and imports it in the table.(2 subs)
Private Sub browseaf_Click()
On Error GoTo Err_browseaf_Click
'Declare a variable as a FileDialog object.
Dim fd As FileDialog
Dim vrtSelectedItem As Variant
'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)
'Reference the FileDialog object.
With fd
'Allow the user to select only one file.
.AllowMultiSelect = False
' Show method to display the File Picker dialog box and return the user's action.
'The user pressed the action button.
If .Show = -1 Then
'Step through each string in the FileDialogSelectedItems collection.
Forms![browse_form]![txtfilenameaf].Enabled = True
Forms![browse_form]![txtfilenameaf].SetFocus
For Each vrtSelectedItem In .SelectedItems
'Lstbox.RowSourceType = "value List"
txtfilenameaf.Text = vrtSelectedItem
Next vrtSelectedItem
'The user pressed Cancel.
Else
Set fd = Nothing
Exit Sub
End If
End With
'DoCmd.SetWarnings False
MsgBox "You selected: " & txtfilenameaf.Text
Af1
' Set form controls
'Forms![browse_form]![txtfilenameaf].Enabled = True
'Forms![browse_form]![txtfilenameaf].SetFocus
Forms![browse_form]![browseaf].Enabled = True
'Set the object variable to Nothing.
Set fd = Nothing
Exit_browseaf_Click:
Exit Sub
Err_browseaf_Click:
MsgBox Err.Description
Resume Exit_browseaf_Click
End Sub
--------------------------------------------------------------------------
Public Sub Af1()
On Error GoTo af1_Err
DoCmd.SetWarnings False
DoCmd.TransferText acImportDelim, "Af1", "Af1", txtfilenameaf.Text, False, ""
af1_Exit:
Exit Sub
af1_Err:
DoCmd.SetWarnings True
MsgBox Error$
Resume af1_Exit
End Sub