Why getting error: Error 3251 - Operation is not supported for this type of object

I'm using this code to attempt to write or edit records in a table from a command button on a form.  

Private Sub cmdCreateInvoice_Click()

Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("tblInvoices")

    With rs
        .FindFirst "[WorkOrderID]=" & Me.txtWorkOrderID

        If .NoMatch = True Then
            .AddNew
            !WorkOrderID = Me.txtWorkOrderID
            !InvoiceDate = Me.txtDate
            !SalesPerson = Me.cboSalesperson
            !ShippedVia = Me.cboShippedVia
        Else
            .Edit
        End If
        !WorkOrderID = Me.txtWorkOrderID
        !InvoiceDate = Me.txtDate
        !SalesPerson = Me.cboSalesperson
        !ShippedVia = Me.cboShippedVia
        .Update
    End With
    
rs.Close
Set rs = Nothing

End Sub

Open in new window


What am I doing wrong?

--Steve
SteveL13Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
try this revision

remove end if from line 17 and place it after line 22

Private Sub cmdCreateInvoice_Click()

Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("tblInvoices")

    With rs
        .FindFirst "[WorkOrderID]=" & Me.txtWorkOrderID

        If .NoMatch = True Then
            .AddNew
            !WorkOrderID = Me.txtWorkOrderID
            !InvoiceDate = Me.txtDate
            !SalesPerson = Me.cboSalesperson
            !ShippedVia = Me.cboShippedVia
        Else
            .Edit

        !WorkOrderID = Me.txtWorkOrderID
        !InvoiceDate = Me.txtDate
        !SalesPerson = Me.cboSalesperson
        !ShippedVia = Me.cboShippedVia
        .Update
		End If
    End With
    
rs.Close
Set rs = Nothing

End Sub
                                  

Open in new window

Rey Obrero (Capricorn1)Commented:
oops missed another .update line on the .Addnew record

Private Sub cmdCreateInvoice_Click()

Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("tblInvoices")

    With rs
        .FindFirst "[WorkOrderID]=" & Me.txtWorkOrderID

        If .NoMatch = True Then
            .AddNew
            !WorkOrderID = Me.txtWorkOrderID
            !InvoiceDate = Me.txtDate
            !SalesPerson = Me.cboSalesperson
            !ShippedVia = Me.cboShippedVia
	   .Update
        Else
            .Edit

        !WorkOrderID = Me.txtWorkOrderID
        !InvoiceDate = Me.txtDate
        !SalesPerson = Me.cboSalesperson
        !ShippedVia = Me.cboShippedVia
        .Update
		End If
    End With
    
rs.Close
Set rs = Nothing

End Sub
                                  

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dale FyeOwner, Developing Solutions LLCCommented:
Actually, you should be able to replace all of this:
    With rs
        .FindFirst "[WorkOrderID]=" & Me.txtWorkOrderID
        If .NoMatch = True Then
            .AddNew
            !WorkOrderID = Me.txtWorkOrderID
            !InvoiceDate = Me.txtDate
            !SalesPerson = Me.cboSalesperson
            !ShippedVia = Me.cboShippedVia
        Else
            .Edit
        End If
        !WorkOrderID = Me.txtWorkOrderID
        !InvoiceDate = Me.txtDate
        !SalesPerson = Me.cboSalesperson
        !ShippedVia = Me.cboShippedVia
        .Update
    End With

Open in new window

With:
    With rs
        .FindFirst "[WorkOrderID]=" & Me.txtWorkOrderID
        If .NoMatch = True Then
            .AddNew
        Else
            .Edit
        End If
        !WorkOrderID = Me.txtWorkOrderID
        !InvoiceDate = Me.txtDate
        !SalesPerson = Me.cboSalesperson
        !ShippedVia = Me.cboShippedVia
        .Update
    End With

Open in new window

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Gustav BrockCIOCommented:
Dale is right, though WorkOrderID wouldn't need an update:
    With rs
        .FindFirst "[WorkOrderID]=" & Me.txtWorkOrderID
        If .NoMatch = True Then
            .AddNew
            !WorkOrderID = Me.txtWorkOrderID
        Else
            .Edit
        End If
        !InvoiceDate = Me.txtDate
        !SalesPerson = Me.cboSalesperson
        !ShippedVia = Me.cboShippedVia
        .Update
    End With

Open in new window

/gustav
Dale FyeOwner, Developing Solutions LLCCommented:
;-)

Dale
PatHartmanCommented:
And finally, why not use a bound form?  That is what Access is all about.  If you are not going to use the RAD features of Access, there are much better application development platforms.
SteveL13Author Commented:
Actually in this case I was able to and should all along have just used a bound form.  But all of the other code examples are sure to come in handy at some point.  Thanks all!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.