Adding a record to a table

S

Steven Revell

Hi,

I want to use code to add a new record (made up of 4
strings and 1 date) and populate it with data i have
collected. I also need to add the record at the end of the
table.

Thanks for any help,

Steven
 
M

Marshall Barton

Steven said:
I want to use code to add a new record (made up of 4
strings and 1 date) and populate it with data i have
collected.

In what context? If in codem you could execute an INSERT
INTO query, but there are other ways too.
I also need to add the record at the end of the table.

There is no such thing as "the end of the table". The
**only** way you can see data from a table in a particular
order is to have a query that sorts the data.
 
S

Steven Revell

Thanks for replying,

I want to add a record to a table using code.

The code I have performs a filesearch of all the files on
a CD or directory and ends up with 4 entries for each file
found. I want to add data for each file to a predefined
table.

Hope that makes more sense,

Cheers,
Steven
 
M

Marshall Barton

Steven said:
I want to add a record to a table using code.

The code I have performs a filesearch of all the files on
a CD or directory and ends up with 4 entries for each file
found. I want to add data for each file to a predefined
table.

Check Help for the details of using an INSERT INTO query.
You will probably end up with something like:

Dim db As Database
Dim strSQL As String
On Error GoTo ErrHandler

Do Until nomorefiles
' Gather data from filesearch
. . .
' Now, save data to thetable
Set db = CurrentDb()
strSQL = "INSERT INTO thetable " _
& "(fieldA, fieldB, fieldC, fieldD) " _
& "VALUES(value1, value2, value3, value4)"
db.Execute strSQL, dbFailOnError
' locate next file
Loop

ExitHere:
Set db = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ExitHere
End Sub
--
Marsh
MVP [MS Access]

 

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