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

SQL Update only working on 1st 2 rows of List Box

markmcgookin
648 Expert 512MB
This is a strange one!

One minute, everything worked fine, then suddenly I don't know if i did anything, but this started happening.

I have a listbox, populated with 3 values (UserID, userName As Name, status AS AR_Status)

I have a button that (amongst other things) will update the status field to "Inactive" Now.... here's the weird thing, it only works on the top two rows of the list box?!?

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnARLogOff_Click()
  2.  
  3. Dim rs As DAO.Recordset
  4. Dim sqlStr As String
  5. Dim sqlStr2 As String
  6. Dim sqlStr3 As String
  7. Dim username As String
  8. Dim Tvalue As String
  9. Dim LDate As String
  10. Dim status As String
  11. Dim stDocName As String
  12.  
  13. Tvalue = Time
  14. LDate = Date
  15. Booking = "Inactive"
  16. Istatus = "Inactive"
  17.  
  18. username = Me.List14.Column(0)
  19.  
  20. sqlStr = "SELECT bookingStatus " & _
  21.          "FROM tblBooking " & _
  22.          "WHERE userID= '" & username & "'"
  23.  
  24. Set rs = CurrentDb.OpenRecordset(sqlStr)
  25.  
  26. Do While Not rs.EOF
  27.  
  28. sqlStr2 = "UPDATE tblBooking SET finishTime =#" & Tvalue & "#, finishDate =#" & LDate & "#, bookingStatus ='" & Booking & "' "
  29. sqlStr3 = "UPDATE tblUser SET Status = '" & Istatus & "' WHERE UserID = '" & username & "'   "
  30.  
  31. DoCmd.RunSQL sqlStr2
  32. DoCmd.RunSQL sqlStr3
  33. rs.MoveNext
  34.  
  35. Loop
  36.  
  37. MsgBox "All your jobs have been Closed"
  38.  
  39. stDocName = "ARRefresh"
  40. DoCmd.RunMacro stDocName
  41.  
  42. End Sub
  43.  
I can not find any reason why it would work perfectly, repeatidly for two rows... and not the others. If I add new rows exactly the same as the top two (except for the PK) it still wont work, I'm absoloutly stumped!

I'll upload the db as a .rar for anyone who wants to see this!

www.cmdclan.co.uk/Temp/jr_system.rar

Thanks for any help or even an idea why! hehe.

*EDIT* Sorry, it is on the ARsim Form
Jan 11 '07 #1
1 1360
markmcgookin
648 Expert 512MB
Got it fixed! Sorry!

Just moved the update outside the loop. Still can't figure out why it worked for 2 and not the others though.

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnARLogOff_Click()
  2.  
  3. Dim rs As DAO.Recordset
  4. Dim sqlStr As String
  5. Dim sqlStr2 As String
  6. Dim sqlStr3 As String
  7. Dim username As String
  8. Dim Tvalue As String
  9. Dim LDate As String
  10. Dim status As String
  11. Dim stDocName As String
  12.  
  13. Tvalue = Time
  14. LDate = Date
  15. Booking = "Inactive"
  16. Istatus = "Inactive"
  17.  
  18. username = Me.List14.Column(0)
  19.  
  20. sqlStr = "SELECT bookingStatus " & _
  21.          "FROM tblBooking " & _
  22.          "WHERE userID= '" & username & "'"
  23.  
  24. Set rs = CurrentDb.OpenRecordset(sqlStr)
  25.  
  26. Do While Not rs.EOF
  27.  
  28. sqlStr2 = "UPDATE tblBooking SET finishTime =#" & Tvalue & "#, finishDate =#" & LDate & "#, bookingStatus ='" & Booking & "' "
  29.  
  30. DoCmd.RunSQL sqlStr2
  31.  
  32. rs.MoveNext
  33.  
  34. Loop
  35.  
  36. sqlStr3 = "UPDATE tblUser SET Status = '" & Istatus & "' WHERE UserID = '" & username & "'   "
  37.  
  38. DoCmd.RunSQL sqlStr3
  39.  
  40. MsgBox "All your jobs have been Closed"
  41.  
  42. stDocName = "ARRefresh"
  43. DoCmd.RunMacro stDocName
  44.  
  45. End Sub
  46.  
Jan 11 '07 #2

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

Similar topics

7
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a...
8
by: Lauren Quantrell | last post by:
In VBA, I constructed the following to update all records in tblmyTable with each records in tblmyTableTEMP having the same UniqueID: UPDATE tblMyTable RIGHT JOIN tblMyTableTEMP ON...
15
by: graham | last post by:
Hi all, <bitching and moaning section> I am asking for any help I can get here... I am at the end of my tether... I don;t consider myself a genius in any way whatsoever, but I do believe I have...
11
by: Siv | last post by:
Hi, I seem to be having a problem with a DataAdapter against an Access database. My app deletes 3 records runs a da.update(dt) where dt is a data.Datatable. I then proceed to update a list to...
20
by: Mark Harrison | last post by:
So I have some data that I want to put into a table. If the row already exists (as defined by the primary key), I would like to update the row. Otherwise, I would like to insert the row. I've...
30
by: Charles Law | last post by:
Here's one that should probably have the sub-heading "I'm sure I asked this once before, but ...". Two users are both looking at the same data, from a database. One user changes the data and...
16
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.