type error in code

  • Thread starter Thread starter FSt1
  • Start date Start date
F

FSt1

greetings all
using access xp.
i am trying to build a form that tracks gas milage. i
have the form, it works. i am using a DOA recordset to
update the table from the form but the update is giving a
error on the set rsstemn.
if i add "dbopendynaset" or "dbOpenTable" as type, i get
runtime error 13 type mismatch
If i leave the type field blank, i get the same error.
Thanks in advance to anyone who can help.
Code as follows:
Private Sub CmdAccept_Click()

Dim Dbstenm As Database
Dim rsstenm As Recordset

Set Dbstenm = CodeDb()
'error on line below.
Set rsstenm = Dbstenm.OpenRecordset("stenmilage",
dbOpenTable)

With rsstenm
.AddNew
!Date = txtDate
!EndMiles = txtEndMiles
!StartMiles = txtStartmiles
!MilesDriven = txtMilesdriven
!CumMiles = txtCumMiles
!GalsUsed = txtGalUsed
!CumGals = txtCumGals
!DolsPerGal = txtDolsPerGal
!Dols = txtDolsPerTank
!CumDols = txtCumDols
!Days = txtDaysPerTank
!MPGTank = txtMPGTank
!CumMPG = txtCumMPG
!DolsPerMile = txtDolsPerMile
!DolsPerDay = txtDolsPerDay
!MilesPerDay = txtMilesPerDay
!Comments = txtComments
.Update
End With
rss10m.Close
Dbs10m.Close
MsgBox (" Record was added.")
Me.Requery
Call Clear_Form

End Sub
 
Since it's not failing on Set Dbstenm = CodeDb(), presumably you've added a
reference to DAO. However, I suspect that you didn't remove the reference to
ADO when you did that.

If you have both references, you'll find that you'll need to "disambiguate"
certain declarations, because objects with the same names exist in the 2
models, and Recordset happens to be one such object. To ensure that you get
a DAO recordset, you'll need to use Dim rsstenm as DAO.Recordset (to
guarantee an ADO recordset, you'd use Dim rsstenm As ADODB.Recordset)

The list of objects with the same names in the 2 models is Connection,
Error, Errors, Field, Fields, Parameter, Parameters, Property, Properties
and Recordset
 
Thank you Doug. that worked. but it did create a slew of
other problems that i had to correct. spelling of the
fields. i spend a half hour just correcting spelling
before it went.
But thank you. i learned something today.
FSt1
 
Back
Top