Solved

How can I update a field in MS Access 2003 via code?

Posted on 2011-03-07
3
224 Views
Last Modified: 2012-05-11
I'm want to keep track of how many times a report is printed.  Here is the code that I have thus far to keep track of the print count.  When I run this, I get a "Field can not be updated." error box.  I'm stumped.  Any suggestions?  

Thank you!

Private Sub btn_incr_prnt_Click()

On Error GoTo Err_btn_incr_prnt_Click

Dim db As Database
Dim rec As Recordset
Dim N As Long

 
Set db = CurrentDb()
Set rec = db.OpenRecordset("Certificates")
N = Me.CertID


MsgBox N
N = N + 1
MsgBox N

Me.CertID = N

Exit_btn_incr_prnt_Click:
    Exit Sub

Err_btn_incr_prnt_Click:
    MsgBox Err.Description
    Resume Exit_btn_incr_prnt_Click
   
End Sub
0
Comment
Question by:NDawg
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 500 total points
ID: 35065416
I don't see what you are doing with the Recordset ?

And where are you updating the field ...?
Here Me.CertID = N  ?

If so, are you sure the report Recordsource is updatable ?

Also, is CertID an control on the Report?  If so, be *sure* the Control Name is different that the Control Source ... eg

txtCertID for the Name.

mx
0
 

Author Closing Comment

by:NDawg
ID: 35065699
Ok.  I'm feeling somewhat sheepish...  I forgot about the duplicated control name.  

Many thanks!
0
 
LVL 75
ID: 35065718
Easy to do. It's especially important in Report.  Glad is was that simple.

mx
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question