Solved

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

Posted on 2011-03-07
3
223 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now