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

Code has broken after upgrade to Access 2010

112 100+
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

✓ answered by zmbd

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(32-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().OpenRecordset(QuerySelect)
Should be:
Set rs = DB.OpenRecordset(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 [DigitalImageDetails](...) 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 [DigitalImageDetails](...) (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.

11 2681
Seth Schrock
2,965 Expert 2GB
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 100+
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 "frmRecordControlBox" and then nothing happens.
May 23 '13 #3
Seth Schrock
2,965 Expert 2GB
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 100+
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 Expert 2GB
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 100+
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 Expert 2GB
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 100+
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 Expert Mod 4TB
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(32-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().OpenRecordset(QuerySelect)
Should be:
Set rs = DB.OpenRecordset(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 [DigitalImageDetails](...) 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 [DigitalImageDetails](...) (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
Redbeard
112 100+
Thanks zmbd that fixed it! I followed you steps and was able to fix all the errors. After I changed Line 23 to the code you suggested and did a Compile, it gave me an error on Line 39, like you predicted. (Run-Time error 3601, Too few parameters Expect 1) The ObjectID field for my DigitalImageDetails table is DIObjectID and not ObjectID as it is for all the other ones. Once I fix that it all ran smoothly.
Thanks
May 27 '13 #11
zmbd
5,501 Expert Mod 4TB
YEA!

Now, two simple things to finish up fixing your code:
Back to Post#9

First:
Line 2: Re-enable your error trapping (Appears I mentioned ";" should have said single quote.." ' " opps - too many programing languages under the old hat. In any case, you should re-enable the code.

Last:
Lines 53 thru 57
Currently read:
Expand|Select|Wrap|Line Numbers
  1. Err_rcdelete_Click: 
  2.     'MsgBox Err.Description + "kgkgkg" 
  3.    ' Resume Exit_rcdelete_Click 
  4.  
Your error message/trap is "disabled" and what is there would be only mildly helpful; however, in this case, even with the minimum, it might have helped you find the error sooner if it had been enabled.
What I suggest is to change this code to something (IMHO) useful such as:
Expand|Select|Wrap|Line Numbers
  1. 'DEFAULT ERROR TRAP
  2. '
  3. 'make sure you have zj_errorlocation defined.
  4.     MsgBox Now() & vbCrLf & _
  5.         zj_errorlocation & vbCrLf & _
  6.          Err.Number & vbCrLf & _
  7.            Err.Description, vbExclamation, _
  8.             "DEFAULT ERROR TRAP"
  9. '
  10. Resume exit_from_error_to_cleanup
  11. '
That last resume line takes my code back to a section where I check that all recordsets are closed and pointers are released.
The "zj_errorlocation" is just a variable I set at the beginning of my modules so that when the users report error I can tell which module/form the error is occurring. It can be omitted.
May 27 '13 #12

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

Similar topics

1
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...
5
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...
2
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...
2
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,...
0
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...
1
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...
5
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...
2
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...
1
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...
1
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. ...
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: 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: 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?
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
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.