Beginner's Help

E

Erik T

I am trying to add data into my table and am not sure of the correct syntax.
Also, I am not sure if I used the correct syntax in opening a table -
dbOpenDynaset. Here is a sampling of my code.

Dim rstRaceHeader As DAO.Recordset
Set rstRaceHeader = dbs.OpenRecordset("tblRaceHeader", dbOpenDynaset)

Dim RaceDate As String
Dim TotalRaces As Integer

' Where Race_Date and Total_Races are fields in tblRaceHeader
With rstRaceHeader
Race_Date = RaceDate
Total_Races = TotalRaces
End With

Thanks for looking at this code. I realize that this is a basic question but
your reply could aid an old programmer.
 
D

Dirk Goldgar

Erik T said:
I am trying to add data into my table and am not sure of the correct
syntax. Also, I am not sure if I used the correct syntax in opening a
table - dbOpenDynaset. Here is a sampling of my code.

Dim rstRaceHeader As DAO.Recordset
Set rstRaceHeader = dbs.OpenRecordset("tblRaceHeader",
dbOpenDynaset)

Dim RaceDate As String
Dim TotalRaces As Integer

' Where Race_Date and Total_Races are fields in tblRaceHeader
With rstRaceHeader
Race_Date = RaceDate
Total_Races = TotalRaces
End With

Thanks for looking at this code. I realize that this is a basic
question but your reply could aid an old programmer.

Are you trying to add a new record or update an existing record? To add
a record using the recordset, you need this:

With rstRaceHeader
.AddNew
!Race_Date = RaceDate
!Total_Races = TotalRaces
.Update
End With

To update an existing record, you need this:

With rstRaceHeader

' ... here would be code to locate the record you
' want to update. Then ...

.Edit
!Race_Date = RaceDate
!Total_Races = TotalRaces
.Update

End With

I'm assuming that you have already set your dbs variable to CurrentDB,
or DBEngine(0)(0), or otherwise to an open Database object representing
the database that contains your table.

I don't see any need for the dbOpenDynaset option in the code you
posted, though it won't hurt.
 

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

Similar Threads


Top