Object Doesn't Support this property or method

C

ChuckW

Hi,

I am a VBA novice who is attempting to move VBA code from one database to
another. The code creates some duplicate records and runs successfully when
I click a command button. I named my command button the same and changed my
code to reflect the different form names. When I click on the command button
in the new database I get an error that says "Object Doesn't support this
property or method". I went into references in the VBA code and there are
five things checked. They match exactly the five checked from the original
database where the button works. Any idea why I am getting this error
message?

I have copied my enhanced VBA code below.

Private Sub NewRecordDuplicateInfo_Click()
On Error GoTo Err_AddRecord_Click

Dim db As Database
Dim rs As Recordset

Set db = CurrentDb()

vbCProtocolID = Forms!Protocol!ProtocolID.Value
DoCmd.GoToRecord , , acNewRec

Forms!Protocol!CustomerName.SetFocus
Forms!Protocol!CustomerName = ""

vbNProtocolID = Forms!Protocol!ProtocolID.Value
OrigProtocolID = vbCProtocolID

strSQL = "INSERT INTO ProtocolProducts (ProtocolID,ItemName, Amount)
SELECT ( " & vbNProtocolID & "), ItemName, Amount FROM ProtocolProducts WHERE
(ProtocolID = (" & OrigProtocolID & "))"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Forms!Protocol.Refresh

Exit_AddRecord_Click:
Exit Sub

Err_AddRecord_Click:
MsgBox Err.Description
Resume Exit_AddRecord_Click

End Sub
 
S

strive4peace

Hi Chuck,

you have this:

vbCProtocolID = Forms!Protocol!ProtocolID.Value
DoCmd.GoToRecord , , acNewRec

if you are trying to go to a new record on THAT form, try this:

'~~~~~~~~~~~~~~~~
'save record if changes have been made
if Forms!Protocol.dirty then
Forms!Protocol.dirty = false
end if

'add new record if not on a new record
if not Forms!Protocol.newrecord then
Forms!Protocol.RecordSet.AddNew
end if
'~~~~~~~~~~~~~~~~

you do not need this code, it is not doing anything:
Dim db As Database
Dim rs As Recordset

Set db = CurrentDb()
'~~~~~~~~~~~~~~~~~

instead of
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True

do this:

currentdb.execute strSQL, dbFailOnError

'~~~~~~~~~~~~~~~
instead of this:
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

do this:

'if in code behind form
if me.dirty then me.dirty = false

'if somewhere else
if Forms!formname.dirty then
Forms!formname.dirty = false
end if


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 

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