Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writing to a table using VBA

Status
Not open for further replies.

ArchonSoft

Programmer
Jan 20, 2003
35
CA
I tried to write into a table using the VBA code.
Here is the way I tried (where "historique" is the table I try to write to):

'variables declare
Dim rstWrite As Recordset
Dim dbsInOut As Database

'References to current database
>>>>Set rstWrite = dbsInOut.OpenRecordset("historique",
dbOpenDynaset)


'write to table historique
With rstWrite
.AddNew
!Nom = Nom
!Statut = Statut
!Lieux = Lieux
!HeureRetour = HeureRetour
!SuiviAppels = SuiviAppels
!Commentaires = Commentaires
End With

The problem appears to the line I identified (>>>>) a window pop telling me that "type mismatch". I have tried all possible type and no type to and nothing works properly, always the same message box.

 
Hi

have you set the database object? - eg:

'variables declare
Dim rstWrite As Recordset
Dim dbsInOut As Database

'References to current database
set dbsInOut = CurrentDb()
>>>>Set rstWrite = dbsInOut.OpenRecordset("historique",
dbOpenDynaset)

also you must have a reference to DAO in your references, this is particularly true if you are using Access2000 or AccessXP

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Reference to DAO is ok and the database object is set, but still have the error.
 
Hi

Cannot actually see anything wrong with it.

Do you also have reference to ADO Library in your references?

if yes try making recordset specific to DAO so

Dim rstWrite As DAO.Recordset

also have you missed out the update line so

With rstWrite
.AddNew
!Nom = Nom
!Statut = Statut
!Lieux = Lieux
!HeureRetour = HeureRetour
!SuiviAppels = SuiviAppels
!Commentaires = Commentaires
.Update
End With

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
It works well with:
Dim rstWrite As DAO.Recordset

Thank's
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top