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

OpenRecordset not usable recordset / .edit not working?

Working on a database on Access, trying to run a query to find a record with the latest date and a 'where' condition.
Error returned is "Run Timer Error '3027' Cannot update. Database or object is read-only"

Following conditions:
Button is clicked on a form that contains a text field for 'fCheckInFor'.
Database 'ToolTests' fields
"CheckOut" is dates in format of "3/15/2019 5:35:31 PM"
"CheckIn" is dates in format of "3/15/2019 5:35:31 PM"
"CheckInFor" is a text field
"ToolNumber" is a text field

Public CheckInTool as String

Private Sub CheckIn_Click()

CheckInTool = "000"
If Me.fCheckInFor = "" Then
MsgBox "Enter Returning User."

Else
Dim dbsUE As DAO.Database
Dim rstUE As DAO.Recordset
Set dbsUE = CurrentDb
Set rstUE = dbsUE.OpenRecordset("SELECT Max([CheckOut]) FROM [ToolTests] WHERE [ToolNumber]= '" & CheckInTool & "'")

With rstUE
.Edit 'error occurs here
!CheckIn = Now()
!CheckInFor = Me.fCheckInFor
.Update
End With
MsgBox "Checked In"
DoCmd.Close acForm, "CheckIn"
End If

End Sub

So the error throws at the .Edit line, I'm unsure where to go from here. would also be fine with tossing the whole thing and going at it from a different direction, I'm not a programmer by job title...
Mar 15 '19 #1
4 2360
Luuk
1,047 Expert 1GB
You should format code like this (use the [CODE/] in the toolbar)!:
Expand|Select|Wrap|Line Numbers
  1. Public CheckInTool as String
  2.  
  3. Private Sub CheckIn_Click()
  4.  
  5. CheckInTool = "000"
  6. If Me.fCheckInFor = "" Then
  7. MsgBox "Enter Returning User."
  8.  
  9. Else
  10. Dim dbsUE As DAO.Database
  11. Dim rstUE As DAO.Recordset
  12. Set dbsUE = CurrentDb
  13. Set rstUE = dbsUE.OpenRecordset("SELECT Max([CheckOut]) FROM [ToolTests] WHERE [ToolNumber]= '" & CheckInTool & "'")
  14.  
  15. With rstUE
  16. .Edit 'error occurs here
  17. !CheckIn = Now()
  18. !CheckInFor = Me.fCheckInFor
  19. .Update
  20. End With
  21. MsgBox "Checked In"
  22. DoCmd.Close acForm, "CheckIn"
  23. End If
  24.  
  25. End Sub
it's much easier to refer to where your error is, at line #16...
Mar 16 '19 #2
Luuk
1,047 Expert 1GB
Back to your problem.

Your are trying to '.Edit' the return values of the 'Select MAX(...' statement, and you cannot do that (they are readonly!)

When you change ling 13 to this:
Expand|Select|Wrap|Line Numbers
  1.   Set rstUE = dbsUE.OpenRecordset("SELECT Max([CheckOut]) AS MaxValue FROM [ToolTests] WHERE [ToolNumber]= '" & CheckInTool & "'")
  2.     Set rstUE = dbsUE.OpenRecordset("SELECT * FROM [ToolTests] WHERE [CheckOut]= " & MaxValue )
  3.  
Or, in other word, get the MaxValue,
and after that,
get the record which 'belongs' to that MaxValue .
Mar 16 '19 #3
twinnyfo
3,653 Expert Mod 2GB
Torque1,

Did Luuk’s solution work for you? That would have been my recommendation also.
Mar 17 '19 #4
Luuk
1,047 Expert 1GB
@twinnyfo: now i know you are on nr#1 position in this list



Maybe you should also have told @Torque1 to use '[CODE/]' tags when posting code....
Attached Images
File Type: png twinnyfo.png (3.5 KB, 778 views)
Mar 17 '19 #5

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

Similar topics

3
by: -Michelle- | last post by:
Hi Using A2003 on XP I am wondering from the MVP's and others, what is the most efficient way (in terms of time to process) of updating data in a table, using the docmd.RunSQL or Recordset ...
25
by: dixie | last post by:
I have some code that adds new records into a table for each ID in a list box when a button on a form is clicked. This works fine. My problem now is that I wish to be able to edit all the records...
5
by: j.mandala | last post by:
Someone is trying to run my Access 2002 database under Access 2003. He has had a number of problems: 1) i used the MSComCt2.ocx for it's Date and Time picker. I can't find it under 2003. Do I...
7
by: Peter Bailey | last post by:
I have a querystring built up in vba and I want to open a recordset based on the sql and pass the date value to a textbox or label for use elsewhere on the form. The recordset isnt working as it...
5
by: zMisc | last post by:
Are there any tricks in updaitng a JOINed recordset? I joned to tables and when I try to change a field on the recordset and update it, I get this error: "Unknown column 'CCDE' in 'where...
1
by: Charlie | last post by:
What properties to you set to make a SQL 2005 recordset updatable? In Access, it's Recordset.edit Recordset!FieldName=SomeValue Recordset.update Any help is appreciated.
2
by: nash2love | last post by:
Hi I am new to V.B . currently i am using MS-Access as backend and V.B 6.0 as front end. now i am creating one table in MS-Access with fields SName and SAge and i entered 15 records with out any...
1
by: sebtus | last post by:
I have the following code to edit an existing record. If DCount("ID", "AssignLoc", " = '" & Me.ID & "'") > 0 Then Set db = CurrentDb Set rs = db.OpenRecordset("AssignLoc") ...
6
by: neelsfer | last post by:
I do race timing. I capture race numbers in a subform, a sequential lapnumber is created, and the racenumber and finishtime are appended in realtime to a specific lap number fields in another...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
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...

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.