OpenRecordset AddNew

Private Sub btnADD_Click()

Dim RS As Recordset

Hi

Below is my code to add a new record to table from values stored in a form (unbound)
However, I receive a run time error 13 'Type Mismatch'

Please can anyone help.
Thanks

Set RS = CurrentDb.OpenRecordset("T12_ReceivedGoods")

With RS
.AddNew

!PurchaseOrderID = Me!POID
!LineNo = Me!LineNo
!DeliveryNo = Me!AdvNoteNumber
!QtyReceived = Me!Rcd
.Update
End With
RS.Close

End Sub
hutchisonjAsked:
Who is Participating?
 
Leigh PurvisDatabase DeveloperCommented:
(lol without having seen the line it occurs on - but still my guess.  Do you have the DAO library referenced?)
0
 
peter57rCommented:
Hi hutchisonj,
> However, I receive a run time error 13 'Type Mismatch'
where?

Pete
0
 
hutchisonjAuthor Commented:
Set RS = CurrentDb.OpenRecordset("T12_ReceivedGoods")

the above line of code is highlighted in yellow
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Leigh PurvisDatabase DeveloperCommented:
Usual culprit - my guess would be

Dim RS As DAO.Recordset
0
 
hutchisonjAuthor Commented:
thanks that has stopped the error message, but the record is not inserting into the table (and giving no error message?)
0
 
hutchisonjAuthor Commented:
i do have dao library referenced
0
 
Leigh PurvisDatabase DeveloperCommented:
Odd that you get no error message of any kind.

Are any of the fields required?  Are they all supplied?
Any of them required to be unique - but aren't necessarily supplied as such?
0
 
Leigh PurvisDatabase DeveloperCommented:
Is the table a local native one?  Or linked to another mdb - or indeed ODBC to a different datasource?

Also, you'd normally open a recordset as
Set RS = CurrentDb.OpenRecordset("T12_ReceivedGoods",dbopendynaset)

If it's local - then a table type (the default under that scenario) should be fine too, but just something to remember if it is external.
0
 
jerryb30Commented:
why the ! for me?
shouldn't it be me.whatever?
0
 
Leigh PurvisDatabase DeveloperCommented:
Hi Jerry, how's you?

Either one should have been fine really.  Both would work in this scenario (assuming they're controls) - but there are indeed distinct and important differences.
There have been a few discussions here on EE alone as to which is best and when to use what.

Markus actually summed it up rather nicely last year.
(Rather then me waffle on here - I'll let him do it ;-)
http://www.experts-exchange.com/Databases/MS_Access/Q_21652154.html
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.