473,425 Members | 1,785 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,425 software developers and data experts.

Problems with an update query

I have a form that has two subforms on it - one of them is continuous and lists a bunch of data about a given service's performance measures, while the other is a single view form where the user selects a measure from a combo box (cbo_Measure). After a measure is selected, the other text boxes in the form are updated with relevant information from the database. I am trying to set it up so that after the user updates the action plan for that measure, the form checks to see if the ActionPlan textbox is empty; if it is empty, I want to update the "ActionPlanCompleted" field to "No," and if there is text in there I want to update it to "Yes." I then requery the other subform to display the change.

Here is the code I have so far -

Private Sub ActionPlan_AfterUpdate()
Dim strSQL As String
Dim strCriteria As String

strCriteria = ""
If Me!ActionPlan.Value = "" Then
strCriteria = "Yes"
Else
strCriteria = "No"
End If

MsgBox (Me!cbo_Measure)
MsgBox (Me![cbo_Measure])
MsgBox (Service_ID)
MsgBox (strCriteria)
strSQL = "UPDATE tbl_Service_PM " & " SET tbl_Service_PM.ActionPlanComplete = " & strCriteria & " WHERE tbl_Service_PM.Service_ID = " & Service_ID & " AND tbl_Service_PM.Measure = " & Me![cbo_Measure]
MsgBox (strSQL)
DoCmd.RunSQL strSQL
Forms![frm_PerformanceMeasure]![sfrm_Service_PM].Requery
End Sub

All of the message boxes are popping up with the correct values in them, except for strCriteria. That shows up as "No" whether the text box is blank or not. I am having three other problems with this -

1. tbl_Service_PM.ActionPlanComplete is not getting updated at all, though I get a message saying that 1 row has been updated.
2. When it runs, it always prompts me for a value of cbo_Measure. For instance, if the value in the combo box is MC3, a prompt pops up for me to give a value for MC3. If I type in anything except for MC3, the message saying how many rows were updated gives me a 0.
3. After the update, the next time I bring the focus to the other subform, I get a Write Conflict error message.

I've been stuck on this for a few hours already this morning, and it's really starting to stress me out.
Sep 4 '07 #1
9 1741
FishVal
2,653 Expert 2GB
Hi, Monroeski.

I think you don't need at all to store strCriteria in the table as soon as value of tbl_Service_PM.ActionPlan is the criteria itself.
Simply retrieve it's value with a query like this
Expand|Select|Wrap|Line Numbers
  1. SELECT *, iif(isnull(tbl_Service_PM.ActionPlan), "No", "Yes") AS ActionPlanComplete FROM tbl_Service_PM;
  2.  
Sep 4 '07 #2
Would IsNull even pick that up? A zero-length string isn't the same thing as Null, is it?

::edit::
nm, just tried it, and it returns correctly. Still not updating the table correctly, though.

None of the forms involved actually uses tbl_Service_PM as a record source, they both use queries (which do contain fields from tbl_Service_PM). Could that be part of the problem? It's really confusing me why it tells me that a record has been updated when I can go into the table and see with my own eyes that it hasn't.
Sep 4 '07 #3
FishVal
2,653 Expert 2GB
Would IsNull even pick that up? A zero-length string isn't the same thing as Null, is it?

::edit::
nm, just tried it, and it returns correctly. Still not updating the table correctly, though.

None of the forms involved actually uses tbl_Service_PM as a record source, they both use queries (which do contain fields form tbl_Service_PM). Could that be part of the problem? It's really confusing me why it tells me that a record has been updated when I can go into the table and see with my own eyes that it hasn't.
????
Is tbl_Service_PM.ActionPlan field value not a strict criteria for ActionPlan being completed?
Sep 4 '07 #4
????
Is tbl_Service_PM.ActionPlan field value not a strict criteria for ActionPlan being completed?
Not sure exactly what you're asking. I can say that the only thing that changes ActionPlanCompleted from yes to no and vice-versa is the ActionPlan text box in this form. It is set up to run the above VBA code AfterUpdate.
Sep 4 '07 #5
FishVal
2,653 Expert 2GB
Not sure exactly what you're asking. I can say that the only thing that changes ActionPlanCompleted from yes to no and vice-versa is the ActionPlan text box in this form. It is set up to run the above VBA code AfterUpdate.
I mean the following.

What a reason to have [ActionPlanCompleted] field in the table as soon as it only indicates whether [ActionPlan] is null or not? Or [ActionPlanCompleted] value is not so strictly depends on [ActionPlan] value?

The problem is that ActionPlan text box is only supposed to be "the only thing that changes ActionPlanCompleted from yes to no and vice-versa".
Sep 4 '07 #6
I mean the following.

What a reason to have [ActionPlanCompleted] field in the table as soon as it only indicates whether [ActionPlan] is null or not? Or [ActionPlanCompleted] value is not so strictly depends on [ActionPlan] value?

The problem is that ActionPlan text box is only supposed to be "the only thing that changes ActionPlanCompleted from yes to no and vice-versa".
I think I see what you're asking. The ActionPlanCompleted field is already in the table beforehand, and every entry is "No." Basically, we'll be rolling this out to the organization with everything blank, then each service inputs their own information. So, the starting value for ActionPlanCompleted is "No," and it will only change to "Yes" after a representative from the service has gone in and added data. Should they happen to go back in to the ActionPlan and delete the information there, I want ActionPlanCompleted to reflect that, so I allowed for it to change back to "No" if that field is null.

I'm starting to have issues with the whole way this thing is set up, I may try to figure out a different way ot track this rather than keep trying to make this one work.
Sep 4 '07 #7
FishVal
2,653 Expert 2GB
I think I see what you're asking. The ActionPlanCompleted field is already in the table beforehand, and every entry is "No." Basically, we'll be rolling this out to the organization with everything blank, then each service inputs their own information. So, the starting value for ActionPlanCompleted is "No," and it will only change to "Yes" after a representative from the service has gone in and added data. Should they happen to go back in to the ActionPlan and delete the information there, I want ActionPlanCompleted to reflect that, so I allowed for it to change back to "No" if that field is null.

I'm starting to have issues with the whole way this thing is set up, I may try to figure out a different way ot track this rather than keep trying to make this one work.
Ok. As you like.
To run the update query you just need to enclose string values assigning to text type fields in single quotation marks .

Expand|Select|Wrap|Line Numbers
  1. strSQL = "UPDATE tbl_Service_PM " & " SET tbl_Service_PM.ActionPlanComplete = '" & strCriteria & "' WHERE tbl_Service_PM.Service_ID = " & Service_ID & " AND tbl_Service_PM.Measure = " & Me![cbo_Measure] & ";"
  2.  
or if tbl_Service_PM.Measure is text type field too, then
Expand|Select|Wrap|Line Numbers
  1. strSQL = "UPDATE tbl_Service_PM " & " SET tbl_Service_PM.ActionPlanComplete = '" & strCriteria & "' WHERE tbl_Service_PM.Service_ID = " & Service_ID & " AND tbl_Service_PM.Measure = '" & Me![cbo_Measure] & "';"
  2.  
Sep 4 '07 #8
Ok. As you like.
To run the update query you just need to enclose string values assigning to text type fields in single quotation marks .

Expand|Select|Wrap|Line Numbers
  1. strSQL = "UPDATE tbl_Service_PM " & " SET tbl_Service_PM.ActionPlanComplete = '" & strCriteria & "' WHERE tbl_Service_PM.Service_ID = " & Service_ID & " AND tbl_Service_PM.Measure = " & Me![cbo_Measure] & ";"
  2.  
or if tbl_Service_PM.Measure is text type field too, then
Expand|Select|Wrap|Line Numbers
  1. strSQL = "UPDATE tbl_Service_PM " & " SET tbl_Service_PM.ActionPlanComplete = '" & strCriteria & "' WHERE tbl_Service_PM.Service_ID = " & Service_ID & " AND tbl_Service_PM.Measure = '" & Me![cbo_Measure] & "';"
  2.  
I actually got the query working (I thought) right before you posted this message, but when I went in to the actual table, instead of just updating the ActionPlanComplete field, it also changed another field from 61 to 3997701 or something like that and a couple of other fields from strings to random symbols. ????

At that point I just decided to drop it until tomorrow, when a cooler head should prevail. : )

Thanks for all the help.
Sep 4 '07 #9
FishVal
2,653 Expert 2GB
I actually got the query working (I thought) right before you posted this message, but when I went in to the actual table, instead of just updating the ActionPlanComplete field, it also changed another field from 61 to 3997701 or something like that and a couple of other fields from strings to random symbols. ????

At that point I just decided to drop it until tomorrow, when a cooler head should prevail. : )

Thanks for all the help.
Put
Expand|Select|Wrap|Line Numbers
  1. Debug.Print strSQL
before
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL strSQL
line and see what query actually runs.
Sep 4 '07 #10

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

Similar topics

3
by: | last post by:
Hello, Sorry to ask what is probably a simple answer, but I am having problems updating a table/database from a PHP/ PHTML file. I can Read From the Table, I can Insert into Table/Database, But...
0
by: Marko Poutiainen | last post by:
Situation: We had to make our SQLServer 2000 database multi-lingual. That is, certain things (such as product names) in the database should be shown in the language the user is using (Finnish,...
11
by: rishi_israni | last post by:
Hi, i am having a strange problem running memory intensive queries on SQL server. I am doing an update on a table with 9 million records from another table with 50 records. the query i am...
2
by: Joshua Moore-Oliva | last post by:
I have a query that is asking me to GROUP a column, yet when I GROUP it it causes an error near GROUP. What is very strange about the following query is that the line list_size_active =...
2
by: Jonathan \(Pickles\) Sklan-Willis | last post by:
Hi All, This is what I want to do: 1. Build a database in Access with certain queries and a query form. (DONE). 2. I now need to use the same form as a form in VB, this will be the front page...
2
by: stuart.d.jones | last post by:
Hi, I'm using a detailsview control with an SqlDataSource control. My Update query isn't working, and I've narrowed it down to the optimistic concurrency parameters - i.e. when I comment them...
1
by: beil.jp | last post by:
Hi All - I'm new to Google Groups and just a novice user of Access, so please forgive me if my question is elementary: I am having a problem using the "update query" for my first time. In my...
12
by: Bruce One | last post by:
For all the ORM i have searched around, I have always found two big problems: 1) To update or delete a set of records you must first bring it to memory. If you are inside a loop and have to do it...
9
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped....
0
by: imusion | last post by:
Hi, I have 2 servers each running AIX and both have a DB2 database setup on them. I'm building a news management application and in our setup we need to have a staging and production setup. So...
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:
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.