Access 2003 code not working in 2007

C

carrie schmid

users select names using Multipik and click on a print preview button using
the following:

Private Sub cmdChosen_Click()
On Error GoTo Err_cmdChosen_Click
Dim aselected() As Variant
Dim strShowIt As String
Dim varItem As Variant
' added'
Dim prm_MyCtl As Control
Dim DB As Database
Dim rs As Recordset
Dim strDelSQL As String

Set DB = CurrentDb

'Unload the records in the Temp table
strDelSQL = " DELETE tblTemp.fullname FROM tblTemp"
DB.Execute strDelSQL

' Get an array filled with the selected items.
Set prm_MyCtl = Me!lstSelected
Set rs = DB.OpenRecordset("Select * From tblTemp")

aselected = mmp.SelectedItems
For Each varItem In aselected
'added'
rs.AddNew
rs!NAME = varItem
rs.Update
Next varItem

Dim stDocName As String

stDocName = "currencysheetsbyname"
DoCmd.OpenReport stDocName, acPreview
Exit_cmdChosen_Click:
Exit Sub

Err_cmdChosen_Click:
MsgBox Err.Description
Resume Exit_cmdChosen_Click

End Sub

PROBLEM: in 2007 I get "type mismatch".
any assistance would be helpful. thanks. Carrie
 
D

Douglas J. Steele

Try changing

Dim rs As Recordset

to

Dim rs As DAO.Recordset

I suspect you'd removed the ADO library from the references in Access 2003,
so it didn't cause an issue there.
 
D

Douglas J. Steele

What line of code is causing the error?

I noticed that in one place you've got

DELETE tblTemp.fullname FROM tblTemp

(which isn't necessary, by the way: you can't delete just a single field,
you're deleting the entire row), but in another you've got

rs!NAME = varItem

Should they both be the same field name?
 
C

carrie schmid

Mr. Steele, thank you so very much, both of your suggestions worked
wonderfully. Have a wonderful day, and thanks for the quick response and
limitless patience.
 

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

Top