473,385 Members | 1,379 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.

Cannot add record

I have a form for entering tire change records that has been working fine for several years.

There are two records created for each tire change, one for the tire that was removed and another for the tire that was installed.

There is also SQL to update the tires table with the current status of the tire(Discarded, In Service, etc.).

Now when I try to enter tire change records I get an error message "Update Tires 2015 You can't go to the specified record". This occurs after the "removal" record is created and the code calls for a new record for the "install".

Upon trying to exit the error message appears "You cannot add or change a record because a related record is required in "tblTires".

The tires are in the table since they are selected from a series of combo boxes based on the tires table. These combos are on a dialog form which when completed is hidden and the variables are defined from this form.

Here is the code I have:
Expand|Select|Wrap|Line Numbers
  1. Case 1  'tire removed and discarded
  2.             If Not Me.NewRecord Then    'be sure you're at a new record
  3.                 DoCmd.GoToRecord , , acNewRec
  4.             End If
  5.  
  6.             If intOldTire <> 1 Then    'if there is a defined old tire
  7.                 If dtOldTire < Forms!frmServices!ServiceDate Then
  8.                     Dim strSQL As String    'set discard to true and InService to False for OldTire in the tires table
  9.                         strSQL = _
  10.                             "UPDATE tblTires " & _
  11.                             "SET tblTires.Discarded = True, tblTires.InService = False " & _
  12.                             "WHERE (((tblTires.TireID) =" & intOldTire & "));"
  13.  
  14.                     CurrentDb.Execute strSQL, dbFailOnError
  15.                 End If
  16.  
  17.                 With Me
  18.                     .txtUpdatedTire = intOldTire                'set tire ID for this record
  19.                     .txtUpdatedTirePosition = intOldPosition    'set position for this record
  20.                     .txtAction = "Removed"                      'set status as removed
  21.                     .txtTreadDepth = intDiscardDepth            'set tread depth
  22.                     .Notes = Forms!frmUpdateTireLocation!txtNotesOldTire
  23.                 End With
  24.  
  25.                 DoCmd.GoToRecord , , acNewRec                       'move to new record
  26.             End If
This is where the code fails.
Below is the code for the "new tire install" record.

Expand|Select|Wrap|Line Numbers
  1.  With Me
  2.                 .txtUpdatedTire = intNewTire                    'set tire ID for this record
  3.                 .txtUpdatedTirePosition = intOldPosition        'set position for this record
  4.                 .txtAction = "Installed"                        'set status as installed
  5.                 .Notes = Forms!frmUpdateTireLocation!txtNotesNewTire
  6.             End With
  7.  
  8.             If dtNewTire < Forms!frmServices!ServiceDate _
  9.                 Or dtNewTire = 0 Then               'there are no service records at a later date
  10.                     Dim strInService As String      'set New Tire InService to True
  11.                         strInService = _
  12.                             "UPDATE tblTires " & _
  13.                             "SET tblTires.InService = True, tblTires.Discarded = False " & _
  14.                             "WHERE (((tblTires.TireID) =" & intNewTire & "));"
  15.                 CurrentDb.Execute strInService, dbFailOnError
  16.                 DoCmd.GoToRecord , , acNewRec                       'move to new record
  17.             End If
Thanks for your assistance!
Knowlton
Aug 15 '13 #1
4 2372
zmbd
5,501 Expert Mod 4TB
Ok,
1) Are you still using the same version of Access that you created the form with?
1a) Which version are you using?
1b)If you've "upgraded" which version have you upgraded to?
1c)If you've "upgraded" is the file still "mdb" or have you upgraded to V2007/V2010/V2013.
2) Is the code failing in the first block of code or the second block of code?
2a) Which line? (insert a STOP in your code at some point prior to where you think the error is occuring, I prefer at the start if the error point is not known. The code will enter DEBUG mode at that point. You can then [F8] to step thru the code until you reach the error line... if it doesn't error, then it may be a timeing issue in the record write)
Aug 15 '13 #2
@zmbd
The version I am using is 2003(Access 2000 file format).

It was created with access 2000. The file is a mdb file. I have inserted the code break and stepped through and the code fails at the "DoCmd.GoToRecord , , acNewRec" line at the end of the first block of code. When stepping through the code and I get to the "DoCmd.GoToRecord , , acNewRec" line, I get the error message "Update Tires(the name of the sub)2499 You can't use the GoToRecord Action or Method on an object in design view"

The first block of code works and the "remove" record is created or at least appears so on the form. However, if I open the table, the record is not there. It fails when trying to go to a new record for the second block(install record).
Aug 15 '13 #3
zmbd
5,501 Expert Mod 4TB
After line 23 insert me.requery, let's make sure that your form has the latest recordset.

As for why you would receive a design view error, that usually only happens when the form is in, well, design view. If you were in that state, please try it again with the form in normal view.
Aug 16 '13 #4
I've figured it out. Somehow the tires table was linked to the wrong file. I don't have a clue how the one table's link got changed but I corrected it and everything is working fine again.
Thanks so much for your help!
Aug 16 '13 #5

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

Similar topics

17
by: Rick | last post by:
Hi all, Is there a MySQL function to get the first record through a query? I would like to open a page of client records with the first one shown. The other records can be accessed from a...
2
by: Dmitry | last post by:
Hello everyone, I have a really simple question here: I have a plain space delimited file that I want to read with WHILE loop 1 line at the time and process each input record as an array of...
5
by: Sami | last post by:
Please bear with me, and if you answer this question, please do it step by step. I am new at Access, not at all sophisticated. I am using Office XP. This will need to be read in Access for...
1
by: terry.statham | last post by:
Hope someone can help me here. I am fairly new to Access. I have set up a database relating to vehicle movements prior to sale. I have a subform based on 'locations' table which is linked to my...
6
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox...
19
by: rich | last post by:
I am building an app using php and postgresql. My questionis this. How do you handle people wanting to make parallel changes to a record. Since in web apps you are doing a select, bring over a...
2
by: Mark Reed | last post by:
Hi All, I have created a multi-user application at work which is working perfectly apart from a small problem which I believe to more a of a user issue (maybe some will set me straight on that...
2
by: Hph | last post by:
I have a repeating problem that I have been able to fix in the past only one way. I get a record that turns from 'english' to "foreign symbols" and then I cannot edit or delete that record. The...
3
prn
by: prn | last post by:
Hi folks, I've got something that's driving me crazy here. If you don't want to read a long explanation, this is not the post for you. My problematic Access app is a DB for keeping track of...
1
by: sprasad123 | last post by:
Need bit of a help with Access to SQL subform queries i have upsized a Access DB. It also has a Access frontend. The upsized went ok. I relinked the Access linked table to SQL. When I try to add a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...

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.