Import text

B

Boon

Hello,

I have a form that has a button that will call vba code to import text file
to a table. A table stores sales information, and the text files contains
new sales information. so it is APPEND per say. In a table I have primary
key set in 2 fields. When I run this vba code, if the data in the text file
is already in the table, it won't append to the table. In the vba code I
turn off the warning by using Docmd.Setwarning False.

This is working perfectly fine. What I want to do is to have a message box
in my form that tells how many rows (records) were added to the table. Says
in the file I have 10 rows, but only 8 rows are new data, so I want to
disply "8 rows has been added to the table".

How can I accomplish this?

Thanks,
Boon
 
D

Dirk Goldgar

Boon said:
Hello,

I have a form that has a button that will call vba code to import text
file to a table. A table stores sales information, and the text files
contains new sales information. so it is APPEND per say. In a table I have
primary key set in 2 fields. When I run this vba code, if the data in the
text file is already in the table, it won't append to the table. In the
vba code I turn off the warning by using Docmd.Setwarning False.

This is working perfectly fine. What I want to do is to have a message box
in my form that tells how many rows (records) were added to the table.
Says in the file I have 10 rows, but only 8 rows are new data, so I want
to disply "8 rows has been added to the table".

How can I accomplish this?


My guess is that you are using DoCmd.RunSQL to execute your append query.
If you suppress warnings, that leaves you know way to see how many records
were actually appended. But if you use the DAO Execute method instead, you
can interrogate the RecordsAffected property of the database object to get
that information.

You didn't post your current code, but here's an example that you can use as
a model:

'------ start of example code ------

With CurrentDb

.Execute "YourAppendQuery", dbFailOnError

MsgBox _
.RecordsAffected & " rows have been added to the table.", _
vbInformation, _
"Import Complete"

End With

'------ end of example code ------
 

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