473,396 Members | 2,013 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,396 software developers and data experts.

Update recordset

82 64KB
Hi, I hope someone can help me. Everything works fine with this code except it won't update the recordset. Any thoughts? I've done about everything I can think of and can't find any help on the Web.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdUpdate_SortOverall_Click()
  2.    Dim Sqlstr As String
  3.    Dim OSS As Integer, Diab As Integer, CVD As Integer, HT As Integer, new_sort As Double, old_sort As Double
  4.    Dim Num_Measures As Integer
  5.    Dim Update_Response As VbMsgBoxResult
  6.    Dim tmpSQL As String
  7.    Dim field_list As String
  8.    Dim rs As ADODB.Recordset
  9.  
  10.    Dim cmd As ADODB.Command
  11.    Dim cnn As New ADODB.Connection
  12.  
  13.     Set cnn = CurrentProject.Connection
  14.     Set cmd = New ADODB.Command
  15.  
  16.  On Error GoTo Err_cmdUpdate_SortOverall
  17.  
  18. field_list = Allfields_except_ID("PracticeTable", "PracticeID")
  19.  
  20. Screen.MousePointer = 11
  21. '01 april 2013 Practice ID and PracticeID removed as field no longer in table
  22.  
  23.      Sqlstr = "         Select PracticeTable.OPNumber," 'PracticeTable.[Practice ID], PracticeTable.PracticeID, PracticeTable.OPNumber, "
  24.      Sqlstr = Sqlstr & "  PracticeTable.PracticeName, PracticeTable.ChangeID, "
  25.      Sqlstr = Sqlstr & "  PracticeTable.OSSDisplay, PracticeTable.OSSScore, "
  26.      Sqlstr = Sqlstr & "  PracticeTable.DMDisplay , PracticeTable.DMScore, "
  27.      Sqlstr = Sqlstr & "  PracticeTable.CVDDisplay, PracticeTable.CVDScore, "
  28.       Sqlstr = Sqlstr & "  PracticeTable.Hypertension_Care, PracticeTable.Hypertension_Care_Score, "
  29.   'old code but ' out flagcurrent, isdeleted, OP0000, and order by
  30.      Sqlstr = Sqlstr & "  SortOverall "
  31.      Sqlstr = Sqlstr & "  FROM PracticeTable "
  32.      Sqlstr = Sqlstr & "    Where (FamilyMedicine=1 or InternalMedicine=1)"
  33.  
  34.  
  35.  Set rs = New ADODB.Recordset
  36. rs.Open Sqlstr, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
  37.  
  38.      Do While Not rs.EOF
  39.           Num_Measures = 0
  40.  
  41.           OSS = AssignRatingValue(Nz(rs!OSSDisplay, ""))
  42.           If OSS > 0 Then Num_Measures = Num_Measures + 1
  43.  
  44.  
  45.           Diab = AssignRatingValue(Nz(rs!DMDisplay, ""))
  46.           If Diab > 0 Then Num_Measures = Num_Measures + 1
  47.  
  48.           CVD = AssignRatingValue(Nz(rs!CVDDisplay, ""))
  49.           If CVD > 0 Then Num_Measures = Num_Measures + 1
  50.  
  51.           'added 01 april 2013 for HT
  52.  
  53.           HT = AssignRatingValue(Nz(rs!Hypertension_Care, ""))
  54.           If HT > 0 Then Num_Measures = Num_Measures + 1
  55.  
  56.           '01 april 2013 added HT to formula and message box
  57.  
  58.           old_sort = Nz(rs!SortOverall, 0)
  59.           If Num_Measures > 0 Then new_sort = Round((OSS + Diab + CVD + HT) / Num_Measures, 2)
  60.  
  61.  
  62.  
  63.  
  64.           If old_sort <> new_sort Then
  65.              Update_Response = MsgBox(rs!PracticeName & " (" & rs!OPNumber & ")" & vbCrLf _
  66.                                       & vbCrLf _
  67.                                       & "OSS  = " & rs!OSSDisplay & "(" & rs!OSSScore & ")" & vbCrLf _
  68.                                       & "Diab = " & rs!DMDisplay & "(" & rs!DMScore & ")" & vbCrLf _
  69.                                       & "CVD  = " & rs!CVDDisplay & "(" & rs!CVDScore & ")" & vbCrLf _
  70.                                       & "HT  = " & rs!Hypertension_Care & "(" & rs!Hypertension_Care_Score & ")" & vbCrLf _
  71.                                       & vbCrLf _
  72.                                       & "Current SortOverall = " & old_sort & vbCrLf _
  73.                                       & "Calculated SortOverall: (" & OSS & " + " & Diab & " + " & CVD & " + " & HT & ") / " & Num_Measures & " = " & new_sort & vbCrLf _
  74.                                       & vbCrLf _
  75.                                       & "Would you like to update this practice's SortOverall?" _
  76.                             , vbYesNo _
  77.                             , "Update SortOverall?")
  78.  
  79.              If Update_Response = vbYes Then
  80.  
  81.  
  82.                  DoCmd.RunSQL tmpSQL, False
  83.  
  84.                  tmpSQL = "Update PracticeTable " _
  85.                        & "  Set     PracticeTable.SortOverall=" & new_sort _
  86.                        & " where PracticeTable.OPNumber=" & rs!OPNumber 
  87.  
  88.                 cnn.BeginTrans
  89.                    With cmd
  90.                       .CommandType = adCmdText
  91.                       .ActiveConnection = cnn
  92.                       .CommandText = tmpSQL
  93.                       .Execute
  94.                    End With
  95.                 cnn.CommitTrans
  96.                 tmpSQL = ""
  97.              End If
  98.  
  99.           End If
  100.  
  101.           rs.MoveNext
  102.      Loop
  103.  
  104.  
  105. Exit_cmdUpdate_SortOverall:
  106.  
  107.      Set rs = Nothing
  108.      Screen.MousePointer = 1
  109.  
  110.      Exit Sub
  111.  
  112. Err_cmdUpdate_SortOverall:
  113.     Screen.MousePointer = 1
  114.     MsgBox "Error while updating SortOverall:" & Err.Description & Err.Number
  115.     DoCmd.SetWarnings True
  116.  
  117.     Resume Exit_cmdUpdate_SortOverall
  118. End Sub
  119.  
  120.  
  121.  
  122.  
Apr 9 '13 #1
6 2084
r035198x
13,262 8TB
Write out the SQL that you are using to run the update and check that it is correct. Run it durectly against the database to see if it works there. Maybe it's not matching the values in your where clause.
Apr 9 '13 #2
barbarao
82 64KB
When I enter the SQL code and specify which OPNumber to update, it works fine. the problem seems to be
Expand|Select|Wrap|Line Numbers
  1. " where PracticeTable.OPNumber=" & rs!OPNumber 
. Any other suggestions? Much appreciated.
Apr 9 '13 #3
barbarao
82 64KB
Specifically it is saying the value in rs!OPNumber is not a valid column name. The column name is OPNumber and the rs!OPNumber is a value in the column for which I want the recordset to be updated with Line 85.
Apr 9 '13 #4
barbarao
82 64KB
Figured it out but new problem. Changed line 86 to be
Expand|Select|Wrap|Line Numbers
  1. & " where PracticeTable.OPNumber= '" & rs!OPNumber & "';"
but line 73 gives me unconsistent results if adding 0 + 0 +0 +0. Any thoughts anyone?
Apr 9 '13 #5
r035198x
13,262 8TB
Are you using the correct types? Integer vs String
Apr 9 '13 #6
barbarao
82 64KB
Yes, all are Integer. Figured it out. Added a new line.

Expand|Select|Wrap|Line Numbers
  1.  If Num_Measures = 0 Then new_sort = 0
those with zero number of measures now working. Thanks.
Apr 9 '13 #7

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

Similar topics

4
by: Tom | last post by:
I want to open a recordset object on an .asp page. When I open the recordset I would like to use a stored procedure that expects a parameter to be passed for the stored procedure. I will then use...
2
by: Joseph Markovich | last post by:
I'm having some trouble with VB in Access 2000. I have a form that the user enters in just one number (in this case, it's a base salary) and then the program is going to do a bunch of math (which...
2
by: Corey | last post by:
I am missing something here. I have a pop up form (loads from the "main form")that displays multiple command buttons. When a user selects a particular button, the recordset from the main form...
1
by: WStoreyII | last post by:
I am trying to make a finances database. I have a master table which contains transaction header info and then a line details table. What i want is to make a reconcile query where i can see...
1
by: teenagelcruise | last post by:
hi, i have a problem with my code which is i cannot update and addnew data into the database but i can delete the data.plz give me an idea.this is my code that i wrote. <html> <head> <meta...
2
by: wallconor | last post by:
Hi, I am having a problem using Dreamweaver CS3 standard recordset paging behavior. It doesn’t seem to work when I pass parameter values from a FORM on my search page, to the recordset on my...
2
by: Jollywg | last post by:
I'm using 2 forms one is a customer entry form and the second is an invoice entry form for that particular customer. I'm sending the invoice form the customer id number to keep the link up. The...
3
pbala
by: pbala | last post by:
Hello, I have problem in reset the new password with old one.For that I used the code as Set rstreset = New ADODB.Recordset strtable = "Update USERS SET rstreset!Password = '" & upwd & "' where...
4
by: Ceylon | last post by:
Hi I have following code to find the hashvalue in HashValue colunm and update the Time in BST column. But i breaks in (objRecordSet.Fields.Item("BSTime") = Time) here (**Edit Line #23 **). Pls...
0
by: Kris Forsyth | last post by:
I have a system that I enter my days work then at the weeks end it generates the invoice for the week with each days work in it. I then want to create a form that registers all those days worked for...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.