473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Updated info in data and save activities done into a Log Table

Hi,

I am creating a button that enables to perform an update or a swap of information from old to new. Example, same User but change of old address to new address after I select from a list option.

At the same time, when the update is perform, the old information is saved into a Log Table.

I got error after I program the script "Field cannot be updated".

Pls advise.

Thanks
May 14 '08 #1
3 1101
Stewart Ross
2,545 Expert Mod 2GB
Hi desserts. You'll need to post the code you are using so we can help you with this error. There are many ways to accomplish an update, but without seeing what you are doing we cannot help you pinpoint the problem.

The simplest approach to such updates is to build an SQL statement as a string and use the DoCmd.RunSQL or CurrentDB.Execute commands to run the SQL, but like all update queries (whether run from code or from the query editor) the resultant query has to be updatable for it to work. It is possible to build a correctly-formatted SQL statement which is not updatable, and we cannot guess at this without seeing what you are doing.

Please post your code, including any SQL you generate, so we can advise further.

-Stewart
May 14 '08 #2
Hi Stewart,

I'd appreciate the help. Here is the code

Private Sub Command38_Click()
On Error GoTo Err_Command38_Click

If MsgBox("Confirm?", 1) = 2 Then
Exit Sub
End If
If [Status] = "Assigned" Then
MsgBox "Status is not changed"
Exit Sub
End If

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Set HPDB = CurrentDb
HPno = [Battery_BattID]
BattID = [Emp Data_HP no]


'Update new Battery data
Set rstEmployees = HPDB.OpenRecordset("Battery")
With rstEmployees
.Index = "PrimaryKey"
.Seek "=",[List39].Value
.Edit
![Status] = "Assigned"
'If ![Date First Issued] = "" Then
' ![Date First Issued] = Date
'End If
.Update
End With
rstEmployees.Close

'Update link in Battery Table
Set rstEmployees = HPDB.OpenRecordset("Emp Data")
With rstEmployees
.Index = "PrimaryKey"
.Seek "=", HPno
.Edit
![BattID] =[List39].Value
.Update
End With
rstEmployees.Close

'Save to Log
Set rstEmployees = HPDB.OpenRecordset("Log Job", dbOpenTable)
With rstEmployees
.AddNew
![Date Reported] = Date & " " & Time
![HP Number] = HPno
![BattID] = BattID
![Replacement BattID] =[List39].Value
![Problem Definition] = [Text18]


![User Name] = [User Name]
![UserID] = [UserID]
![Dept] = [Dept]
![Remark] = [Remark] '& " Warranty Date: " & [Warranty Date] & ". "
![Status] = [Status]
If ([Status] = "Lost") Or ([Status] = "Repairing") Or ([Status] = "Beyond Repair") Then
![Out] = Date
![In] = Date
End If
![Out] = Date
.Update
End With
rstEmployees.Close


HPDB.Close
DoCmd.Close
MsgBox "Updated"
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Swap Battery"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command38_Click:
Exit Sub

Err_Command38_Click:
MsgBox Err.Description
Resume Exit_Command38_Click

End Sub

Private Sub Command41_Click()
On Error GoTo Err_Command41_Click


Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

Exit_Command41_Click:
Exit Sub

Err_Command41_Click:
MsgBox Err.Description
Resume Exit_Command41_Click

End Sub

Private Sub Combo25_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[HP Number] = '" & Me![Combo25] & "'"
Me.Bookmark = rs.Bookmark
End Sub

Private Sub List39_AfterUpdate()


'MsgBox Me![List39].Value

Set HPDB = CurrentDb
Set rstEmployees = HPDB.OpenRecordset("Battery")
With rstEmployees
.Index = "PrimaryKey"
.Seek "=",[List39].Value
[Text43] = ![BattID]
[Text45] = ![Battery]
[Text49] = ![Warranty Date]
End With
rstEmployees.Close

HPDB.Close

End Sub
May 15 '08 #3
Stewart Ross
2,545 Expert Mod 2GB
Thanks for the code listing. You are not using SQL updates, which are simpler than using recordsets to do so. Looking at the recordset code overall you are using Edit/Update OK, but the updates are dependent on the seeks resulting in a match. I would recommend you verify that the record you seek is indeed being found. Otherwise it is not at all obvious from this end what might be going wrong.

In what line of the code posted does the error occur? What steps have you taken so far to set breakpoints, step through the code, and test values as the code runs? What have you seen in the debugger when you look at values for the various fields involved?

-Stewart
May 15 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: elyob | last post by:
Hi, I'm looking at storing snippets of details in MySQL about what credit cards a business excepts. Rather than have a whole column for Visa, another for Amex etc ... I am looking at having a...
3
by: Tom Turner | last post by:
Here's the background on my situation. The question follows --- We have 600 units of mail going from our business to various Post Offices every morning. Every unit is accompanied by a paper...
1
by: rob | last post by:
I built a combo box that contains names of people. A user can chooses a person from the combo box, the next couple of the text boxes will show the corresponding address of that person. I used...
2
by: Mark Reed | last post by:
Hi all, Scenario: I have about 10 people using a front end database which only 2 have the privilege to update the information. This is done by pasting the contents of a notepad report into a...
4
by: vulcaned | last post by:
Hi All, Hopefully I explain this well........ In Access97 I have a form which has a tab control on it, each tab has a sub-form which is bound to its appropriate table(I'll call them 'Detail'...
3
by: Patrick McGuire | last post by:
I am instantiating several custom objects from a subset of data contained in an XML file. I then might edit these objects and save the changes back to the XML file. However, I want to compare the...
2
by: rustyc | last post by:
Well, here's my first post in this forum (other than saying 'HI' over in the hi forum ;-) As I said over there: ... for a little side project at home, I'm writing a ham radio web site in...
5
by: dos360 | last post by:
Hello, I have two tables, one is a list of activities, the other a list of participants. I want to insert one record in the activities table and then using its identity column as foreign key, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.