473,569 Members | 2,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Code has broken after upgrade to Access 2010

112 New Member
I have just upgraded to Access 2010 (64 bit) from Access 2007. There were a few minor issues in the database which I have resolved but this one piece of code just won’t work. I do not write VBA but have a rudimentary understanding of it. This code was not written by me and I am still trying to understand why it doesn’t work? I have posted the code below; this is what it is supposed to do: I have a main form that displays each record. The form is run from a query that combines one main table and 3 sub tables. The code is connected to a button on a pop-up form that when clicked, deletes the current record on the main form, from all the tables that it is run off. The problem is nothing happen? I don’t even get an error message and request to debug? I am hoping that it is a simple change that has to do with the upgrade as it worked in 2007. Any help is appreciated.

Thanks
Expand|Select|Wrap|Line Numbers
  1. '---------------------------------
  2.     'Declaration of the variables
  3.     '---------------------------------
  4.  
  5.     Dim rs As Recordset         'recordset use to get the objectId of the current record
  6.     Dim QuerySelect As String   'represents the query to gather info
  7.     Dim ObjectID As String      'represents the deleted objectId
  8.  
  9.     '--------------------------------
  10.     'End of declaration
  11.     '--------------------------------
  12.  
  13.     'Close the RecordControlBox
  14.     DoCmd.Close acForm, "frmRecordControlBox"
  15.  
  16.     'Retrieving data from the record to be deleted
  17.     QuerySelect = "Select ObjectID From Description where Description.[Accession Number] = '" & Forms!frmDescription!txtAccNum.Value & "'"
  18.     Set rs = CurrentDb().OpenRecordset(QuerySelect)
  19.  
  20.     'going to the last record then come back to the first to make RS.RecordCount effective
  21.     rs.MoveLast
  22.     rs.MoveFirst
  23.  
  24.     'check if there is only 1 record, should not delete a whole bunch of record at the same time
  25.     If rs.RecordCount = 1 Then
  26.  
  27.         ObjectID = CStr(rs![ObjectID])
  28.  
  29.         'building all the queries to delete every objectId in every table
  30.         CurrentDb().Execute ("DELETE FROM [Condition Info] WHERE [Condition Info].[ObjectID]= " + ObjectID)
  31.         CurrentDb().Execute ("DELETE FROM [Treatment Info] WHERE [Treatment Info].[ObjectID]= " + ObjectID)
  32.         CurrentDb().Execute ("DELETE FROM [DigitalImageDetails] WHERE [DigitalImageDetails].[ObjectID]= " + ObjectID)
  33.  
  34.         Forms!frmDescription!rcdcontrol.SetFocus
  35.         DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
  36.         DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
  37.  
  38.     Else
  39.         MsgBox "An error occured while retrieving ObjectID of the artifact. No record have been deleted"
  40.     End If
  41.  
  42. Exit_rcdelete_Click:
  43.     Exit Sub
  44.  
  45. Err_rcdelete_Click:
  46.     'MsgBox Err.Description + "kgkgkg"
  47.     Resume Exit_rcdelete_Click
  48.  
  49. End Sub
May 23 '13 #1
11 2693
Seth Schrock
2,965 Recognized Expert Specialist
In your VBA editor, click in the gray area to the left of the code to insert a breakpoint at line 14 of your code and then try to run your code. If your code is being ran, the line will be highlighted in yellow (if colors are the default colors). If not, then the link between the button and its code is broken. Go into the design view of your popup form and view the properties of the button. Click on the ellipsis button (the three dots) and make sure that it goes to the correct procedure.
May 23 '13 #2
Redbeard
112 New Member
I have inserted the break point and nothing has changed. I also have checked it is running the right events procedure which it is. I should have said that the only think it does when I click the button is to close the pop-up form "frmRecordContr olBox" and then nothing happens.
May 23 '13 #3
Seth Schrock
2,965 Recognized Expert Specialist
Okay, so the code is running. My guess is that the values aren't what you expect them to be. If you step through the code line by line, you can test your variables and properties in the immediate window.
May 23 '13 #4
Redbeard
112 New Member
I have found the immediate window but have not idea how to use it to "step through the code line by line, you can test your variables and properties"? Sorry I don't have a lot of experanice with VBA.
May 23 '13 #5
Seth Schrock
2,965 Recognized Expert Specialist
If you removed the breakpoint, add it again on line 14. When your code stops at that line, you can step through the code line by line by pressing the F8 key. Whichever line is highlighted is the one that will be executed next. To test your variables and properties you just type a question mark followed by the variable name or the property name. For example, you can find out what the record count is by typing the following into the immediate window when line 25 is highlighted:
?rs.RecordCount
Then press enter it will give you a number on the next line of the immediate window. With line 30 highlighted, type in ?ObjectID to verify that it is what you would expect.

I would also suggest adding an additional argument when you run your delete queries. For example, I would replace lines 30 -32 with
Expand|Select|Wrap|Line Numbers
  1. Dim db As DAO.Database
  2. Set db = CurrentDb
  3.  
  4. db.Execute "DELETE FROM [Condition Info] WHERE [Condition Info].[ObjectID]= " + ObjectID, dbFailOnError
  5. db.Execute "DELETE FROM [Treatment Info] WHERE [Treatment Info].[ObjectID]= " + ObjectID, dbFailOnError
  6. db.Execute "DELETE FROM [DigitalImageDetails] WHERE [DigitalImageDetails].[ObjectID]= " + ObjectID, dbFailOnError
  7. Set db = Nothing
May 23 '13 #6
Redbeard
112 New Member
Ok, so I did what you said and when I use F8 to go through each line in order it jumps from line 32 to 49 without running the rest of the code. So then I replaced lines 30 to 32 with the new code that you gave me and the same thing happened? I think this is the problem but don't know why it is doing that? or how to fix it? I have posted the updated code below. Any thoughts?


Expand|Select|Wrap|Line Numbers
  1.  Dim rs As Recordset         'recordset use to get the objectId of the current record
  2.     Dim QuerySelect As String   'represents the query to gather info
  3.     Dim ObjectID As String      'represents the deleted objectId
  4.     Dim db As DAO.Database
  5.     Set db = CurrentDb
  6.     '--------------------------------
  7.     'End of declaration
  8.     '--------------------------------
  9.  
  10.     'Close the RecordControlBox
  11.  
  12.     DoCmd.Close acForm, "frmRecordControlBox"
  13.  
  14.     'Retrieving data from the record to be deleted
  15.     QuerySelect = "Select ObjectID From Description where Description.[Accession Number] = '" & Forms!frmDescription!txtAccNum.Value & "'"
  16.     Set rs = CurrentDb().OpenRecordset(QuerySelect)
  17.  
  18.     'going to the last record then come back to the first to make RS.RecordCount effective
  19.     rs.MoveLast
  20.     rs.MoveFirst
  21.  
  22.     'check if there is only 1 record, should not delete a whole bunch of record at the same time
  23.     If rs.RecordCount = 1 Then
  24.  
  25.         ObjectID = CStr(rs![ObjectID])
  26.  
  27.         db.Execute "DELETE FROM [Condition Info] WHERE [Condition Info].[ObjectID]= " + ObjectID, dbFailOnError
  28.         db.Execute "DELETE FROM [Treatment Info] WHERE [Treatment Info].[ObjectID]= " + ObjectID, dbFailOnError
  29.         db.Execute "DELETE FROM [DigitalImageDetails] WHERE [DigitalImageDetails].[ObjectID]= " + ObjectID, dbFailOnError
  30.         Set db = Nothing
  31.  
  32.         Forms!frmDescription!rcdcontrol.SetFocus
  33.         DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
  34.         DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
  35.  
  36.     Else
  37.         MsgBox "An error occured while retrieving ObjectID of the artifact. No record have been deleted"
  38.     End If
  39.  
  40. Exit_rcdelete_Click:
  41.     Exit Sub
  42.  
  43. Err_rcdelete_Click:
  44.     'MsgBox Err.Description + "kgkgkg"
  45.     Resume Exit_rcdelete_Click
  46.  
  47. End Sub
May 24 '13 #7
Seth Schrock
2,965 Recognized Expert Specialist
Since you have error trapping at the end, I would assume that you have a line above what you have provided that says something like On Error GoTo .... Could you provide us with that line as well as the line where the sub is declared? In fact, everything above what you have provided would be helpful.
May 24 '13 #8
Redbeard
112 New Member
Sorry about that, here is the full code start to finish.

Expand|Select|Wrap|Line Numbers
  1. Private Sub rcdelete_Click()
  2. On Error GoTo Err_rcdelete_Click
  3.  
  4.     '---------------------------------
  5.     'Declaration of the variables
  6.     '---------------------------------
  7.  
  8.     Dim rs As Recordset         'recordset use to get the objectId of the current record
  9.     Dim QuerySelect As String   'represents the query to gather info
  10.     Dim ObjectID As String      'represents the deleted objectId
  11.     Dim db As DAO.Database
  12.     Set db = CurrentDb
  13.     '--------------------------------
  14.     'End of declaration
  15.     '--------------------------------
  16.  
  17.     'Close the RecordControlBox
  18.  
  19.     DoCmd.Close acForm, "frmRecordControlBox"
  20.  
  21.     'Retrieving data from the record to be deleted
  22.     QuerySelect = "Select ObjectID From Description where Description.[Accession Number] = '" & Forms!frmDescription!txtAccNum.Value & "'"
  23.     Set rs = CurrentDb().OpenRecordset(QuerySelect)
  24.  
  25.     'going to the last record then come back to the first to make RS.RecordCount effective
  26.     rs.MoveLast
  27.     rs.MoveFirst
  28.  
  29.     'check if there is only 1 record, should not delete a whole bunch of record at the same time
  30.     If rs.RecordCount = 1 Then
  31.  
  32.         ObjectID = CStr(rs![ObjectID])
  33.  
  34.  
  35.  
  36.  
  37.         db.Execute "DELETE FROM [Condition Info] WHERE [Condition Info].[ObjectID]= " + ObjectID, dbFailOnError
  38.         db.Execute "DELETE FROM [Treatment Info] WHERE [Treatment Info].[ObjectID]= " + ObjectID, dbFailOnError
  39.         db.Execute "DELETE FROM [DigitalImageDetails] WHERE [DigitalImageDetails].[ObjectID]= " + ObjectID, dbFailOnError
  40.         Set db = Nothing
  41.  
  42.         Forms!frmDescription!rcdcontrol.SetFocus
  43.         DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
  44.         DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
  45.  
  46.     Else
  47.         MsgBox "An error occured while retrieving ObjectID of the artifact. No record have been deleted"
  48.     End If
  49.  
  50. Exit_rcdelete_Click:
  51.     Exit Sub
  52.  
  53. Err_rcdelete_Click:
  54.     'MsgBox Err.Description + "kgkgkg"
  55.    ' Resume Exit_rcdelete_Click
  56.  
  57. End Sub
May 24 '13 #9
zmbd
5,501 Recognized Expert Moderator Expert
Seth may have you on a good track here; however, let’s do a few housekeeping things:

Please take a look at the first few parts of the following link: >> Before Posting (VBA or SQL) Code.

In particular
For VBA code specifically :
Ensure you have Option Explicit set (See Require Variable Declaration).
Try to compile it. If it doesn't compile for any reason then fix it before posting. If you cannot manage that for any reason, then please explain that clearly - including the error message and which line of your code it appears on.
It is most important to get the minor syntax and other junk cleared up.

This is particularly important for you as If I read this correctly - you moved code from a 32-Bit install to a 64-Bit install of office AND from 2007 to 2010 - there have been some really weird reports about missing links to library references, or wrong links, etc... even when doing an upgrade from Office2010-32 to Office2010-64:

Please confirm that you have a 64Bit installation of Office/Access by doing the following: In the ribbon: [File] in left pane [Help] in the right pane, the installation information will be shown - you should see something like
"Version 14.0.6129.500(3 2-Bit)" for a 32 bit install.
- However, I don't think this is your issue.

I Know you’ve posted some code in post #9, so all of the following is going to reference that code…

Line 23:
Set rs = CurrentDb().Ope nRecordset(Quer ySelect)
Should be:
Set rs = DB.OpenRecordse t(QuerySelect) as you've already set DB = the current database on line 12.
As you have it now, you have two different pointers to the same database.

Also, as best practice, you need to close your record sets and set them to nothing to release the resources correctly. As it is now, there is a potential for your record set to be locked, or memory leakage. (Closing Recordset Vs. Setting Nothing

From your other posts… it sounds like during your stepping that execution jumped from db.Execute "DELETE FROM [DigitalImageDet ails](...) all the way to line 49 (which is blank?) in an error it should have failed all the way to the End Sub at line 57 given the posted code.

SO, let’s say you’ve cleared up any of the compiler errors as I’ve suggested then please:

Line 2: disable by placing a single quote " ' " in front of the line. This is for trouble shooting only, before the command.

Compile, Save, You can leave the VBA open.

Do whatever tasks you need to get this form to open in "normal" use, click on your button, when (if) it errors you should be taken to debug mode and I suspect that it will be on line db.Execute "DELETE FROM [DigitalImageDet ails](...) (although, I halfway expect this to fail at db.Execute "DELETE FROM [Condition Info] – however, that is dependent upon your tables.

Tell us what error you get at that point. PLEASE, provide the EXACT line of code the error occures, the EXACT error number and the EXACT error text. Please, no shortcuts…

You might also want to take a look at setting up your table relationships with cascade update/delete. I typically don't allow cascade delete in my DB due to data integrity checks (once entered, always audited); however, it can be very useful in specific situations.
May 25 '13 #10

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

Similar topics

1
4573
by: phill86 | last post by:
Hi, I have an access 2010 database that I want to convert to an SQL Server database and I need to know if the data macros in access will still work in the SQL database or will i have to create triggers in the SQL Sever database Many Thanks Phill
5
12408
by: jaad | last post by:
Hello, I have a database that was written in access 2007 on my pc. I wanted to work off site with the database so I uploaded it onto my laptop which is loaded with access 2010 beta. When I finished working with the database and return it to my pc(which has access 2007) I can't get it open because Access say that the file is not the right...
2
6700
by: sierra7 | last post by:
It seems Access 2010 is associating an 'input mask' or field type with a combo box when a form is opened, even though there is no Format setting on the control. I have a form which has been running OK for years in Access 2003; it adds an item selected from an inventory listing to either an existing Sales Order or Purchase Order. For historic...
2
7183
by: dougancil | last post by:
I have a user who had deleted some records from a database today using Access 2010. They have an ID field that's autonumbered. They have No Duplicates allowed. When they created a new record today, it was recreating numbers that had already been assigned but deleted. I've read a couple of articles about resetting the autonumber in Access, but I'm...
0
1706
by: Andolino | last post by:
In Access 2010 I get a Write Conflict error - "This record has been changed by another user..." In Access 2007 this Code is working - why? Private Sub Form_BeforeUpdate(Cancel As Integer) Dim dbs As DAO.Database, rst As DAO.Recordset, strCriteria As Variant Set dbs = CurrentDb Set rst = dbs.OpenRecordset("Artikel", dbOpenDynaset)...
1
5240
by: Alan Yim | last post by:
Hi folks, My company recently upgraded our Office suite from 2003 to 2010. The problem in particular is with an Access database that was originally designed in Access 2003. The code in question used work in 2003 (see below code). Private Sub engSave_Click() Dim strSql3 As String 'Archive order number and cost data for engine.
5
49006
by: colsoft | last post by:
I am using Access 2010. Am generating reports for the records, one record per page. The records on the even pages have a light black background shading which appears when am printing. Please i need help on how i can remove those background shading.
2
7313
by: Bill Boord | last post by:
I need to be able to shut off the AutoCorrect "feature" within Access 2010 code. I have utilized Application.SetOption with method strings for other startup requirements, but I cannot seem to find a correct method string to turn off the text replace "feature." I am not talking about the "Track Name AutoCorrect Info" method, but rather the method...
1
8473
dsatino
by: dsatino | last post by:
I have numerous applications built in Access 2000/2003 that all use ODBCdirect workspaces to access various non-Access databases. Unfortunately, ODBCdirect is 'no longer supported'in Access 2010 and when my associates get new PC's, the applications fail. The error message says to switch from DAO to ADO. This is a little curious since ADO is...
1
3424
by: Music Man | last post by:
Greetings All: I built a database in Microsoft SQL Server 2000 and used Microsoft Access 2010 as the front end. The database is used to keep track of "issues" that rise out of my employment. I've been there a long time and now feel the need to start documenting certain occurances. I have 4 tables, one of which is a table called...
0
7694
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7921
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5504
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3651
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2107
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.