"Type Mismatch" re recordset (1 Viewer)

AndyS48UK

Registered User.
Local time
Today, 22:48
Joined
Jun 22, 2002
Messages
59
Hi

I have the following code attached to a command button.

When I run it the code errors out to a "Type Mismatch" error box generated by Access.

I've checked the properties and methods but the highlighted line is the one starting "Set rstSpPrice..."

Private Sub cmdWriteSpPrice_Click()

Dim dbs As Database, rstSpPrice As Recordset

Set dbs = CurrentDb
Set rstSpPrice = dbs.OpenRecordset("tblSpecialPrice", dbOpenTable)

rstSpPrice.AddNew
rstSpPrice!ORDER_NUMBER = txtSpPriceOrderNo.Value
rstSpPrice!ITEM_NUMBER = txtSpPriceItemNo.Value
rstSpPrice!STOCK_CODE = txtSpPriceStockCode.Value
rstSpPrice!DESCRIPTION = txtSpPriceDesc.Value
rstSpPrice!SpPrice = txtSpecialPrice.Value

rstSpPrice.Update
rstSpPrice.CancelUpdate

End Sub

Any help would be appreciated. Thankyou.

I'm using Access 2000

Andy
 

Sohaila Taravati

Registered User.
Local time
Today, 22:48
Joined
Oct 24, 2001
Messages
266
Type Mismatch means that you are trying to link two fields that are not same type. One of your fields in your table is probebly a text field and the other a number or any other combination. Make sure that your fields that you are trying to link in your query are of the same type :)
 

AndyS48UK

Registered User.
Local time
Today, 22:48
Joined
Jun 22, 2002
Messages
59
Thanks Sohaila

I did wonder about that...in fact in the meantime I went back to look at the declaration...as the Vb errored out on the line that contained it.

So I took away the declaration "dim rstSpPrice as recordset" and replaced rstSpPrice with an undeclared "fred"...and it works!!

I just don't understand what's wrong with my declaration though.

Thanks for the pointer...it's one that I'm guilty of getting wrong before so it was a good thought that I should check them. Thanks again.

A
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:48
Joined
Feb 19, 2002
Messages
43,602
If you're using A2K or XP there may be some ADO-DAO confusion. It is best to qualify all objects.

Dim dbs As DAO.Database
Dim rstSpPrice As DAO.Recordset

BTW, what is the rstSpPrice.CancelUpdate doing?
 

AndyS48UK

Registered User.
Local time
Today, 22:48
Joined
Jun 22, 2002
Messages
59
Thanks Pat. Yeah, I am using 2000 so I will do that, thanks.

Cancel Update was supposed to be "switching off" the update. Can't remember which of the (many) books I got it from but it suggested using CancelUpdate so that you didn't automatically save the next record when you switched to it.

I fact the code (once it ran) errored out here...I suspect you know why? I wanted to switch off further updates until they were requested by the onclick event so that the user had the choice to save only particular records.

Thanks again.

A
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:48
Joined
Feb 19, 2002
Messages
43,602
Is there some reason that you are doing this with code rather than using a bound form? I looked up the CancelUpdate method and it doesn't seem to apply to a form. It seems to apply to a web page. Check the "Applies to" link.
 

Users who are viewing this thread

Top Bottom