473,466 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Vba Works In 2007, Not 2010 - Loop And Record Update

5 New Member
The code below is a part of a scheduling database that my department uses. The user is able to indicate a scheduling priority by request type (the records in FrmPrioritySheet) and then the code is to look at all the requests for the chosen point in time (underlying records in FrmAutoPrioritize) and prioritize them by assigning the appropriate priority level to the request. The user is also able to limit how many hours of each request type can be scheduled (this is regulated using the total hours reference compared to the FrmPrioritySheet.MaxTotal).

This code worked fine in Access 2007. When I try to run this code in 2010, though, it doesn't work. It does not produce an error, it just runs and doesn't set the priority for the underlying records. I set up a message box as part of the loop and it seems to be cycling through the records in FrmPrioritySheet but not ever moving on to the next record in FrmAutoPrioritize. Again, though, this same code works in Access 2007. We are using the 32 bit version of Access 2010.

So, I guess I have two questions. Since I know the code works in 2007, does anyone have any thoughts on why it may not work the same in 2010? All references are set the same (except 2007 is using VB6 and 2010 is using VB7, although from what I read it shouldn't have any impacts). There is similar code elsewhere in the db (comparing two recordsets from forms and updating them based off of each other) that is also not working and I assume if I can figure out why this one isn't I can fix that as well. And secondly, perhaps to avoid that issue, is there a better way to do this? For example, to open up the recordsets without opening the forms? I inherited this code and although I can understand what it is doing, I do not know enough to understand all the other ways this same thing could be accomplished. Maybe the issue will follow a rewrite to a different method but perhaps not.



Expand|Select|Wrap|Line Numbers
  1. 'Open auto-prioritize form, include request data that will be manipulated    
  2.         'Includes filters from request sheet    
  3.     DoCmd.OpenForm "FrmAutoPrioritize", acNormal, , , acFormEdit, acHidden
  4.         'Open priority sheet with default priorities by request type
  5.     DoCmd.OpenForm "FrmPrioritySheet", acNormal, , , acFormEdit, acHidden
  6.  
  7.  
  8.     Forms!FrmPrioritySheet.Recordset.MoveFirst
  9.  
  10.     ' Cycle through each priority level
  11.     Do While Not Forms!FrmPrioritySheet.Recordset.EOF
  12.           totalHours = 0
  13.         If Not Forms!FrmPrioritySheet.IsCat Then
  14.         Forms!FrmAutoPrioritize.OrderBy = "Type, Duration"
  15.         Forms!FrmAutoPrioritize.OrderByOn = True
  16.         Forms!FrmAutoPrioritize.Recordset.MoveFirst
  17.         ' Cycle through each request
  18.         While (Forms!FrmAutoPrioritize.Type <= Forms!FrmPrioritySheet.PriorityType And _
  19.         Not Forms!FrmAutoPrioritize.Recordset.EOF)
  20.                  If Forms!FrmAutoPrioritize.Type = Forms!FrmPrioritySheet.PriorityType And _
  21.             Forms!FrmAutoPrioritize.Priority = 100 And _
  22.             (totalHours + Forms!FrmAutoPrioritize.Duration) <= Forms!FrmPrioritySheet.MaxTotal Then
  23.              Forms!FrmAutoPrioritize.Priority = Forms!FrmPrioritySheet.PriorityValue
  24.                  End If 
  25.            totalHours = totalHours + Forms!FrmAutoPrioritize.Duration
  26.         End If
  27.     Forms!FrmAutoPrioritize.Recordset.MoveNext
  28.      Wend
  29.      Forms!FrmPrioritySheet.Recordset.MoveNext
  30. Loop
  31.  
Dec 5 '11 #1
9 2938
NeoPa
32,556 Recognized Expert Moderator MVP
I've seen threads recently where similar code problems occur in 2010. The answer was to ensure that the ADODB library is referenced in the project. Also make sure that the project compiles (See When Posting (VBA or SQL) Code).
Dec 6 '11 #2
sierra7
446 Recognized Expert Contributor
What a novel idea! Open two forms, hidden, then cycle through their record sets changing values in the forms.
NeoPa is right to point out that Access 2010 will not have the ADO DB library as it has reverted to used the DAO instead. This is certainly an issue when moving from Access 2003, but 2007 to 2010 should be OK.

With DAO you have to use .Edit and .Update statements before updating a member of the recordset. They are not present in your code but then you are updating fields on a Form, not actually manipulating the recordset.

What worries me more is that I can see two While's and only one MoveNext. There is only one Wend. Is this OK? Personally I use Loop but would still expect two of them.

Are you sure this runs ok in 2007?
S7
Dec 6 '11 #3
sceptar17
5 New Member
NeoPa and sierra7, thank you for your quick replies. To answer your questions:

- I accidentally left off the last two lines of code. I've updated the code above.
- I do know that it runs in 2007. I actually have to have a guy in another department run a couple things in the database for me each week because he has Access 2007.
- Everything does compile.
- I tried adding ab ADODB reference (C:\Program Files\Common Files\System\ADO\msado25.tlb) which was the location referenced at http://allenbrowne.com/ser-38.html. Is that the correct one?
- So now the code stops at the Forms!FrmAutoPrioritize.Priority = Forms!FrmPrioritySheet.PriorityValue line (where it actually passes the priority assignment) and gives an error that I can't assign a value to that object (Run-time 440).

Thoughts?
Dec 6 '11 #4
sierra7
446 Recognized Expert Contributor
Hi again,
First of all I cannot see the line of code you are referring to...

However, question, are you running on a SQL Server backend?
Some recordsets are not updatable unless they are defined with a unique index, and a timestamp field helps.

Can you make your form visible and update the field manually?

S7
Dec 6 '11 #5
sceptar17
5 New Member
Sorry for the confusion - I added the code to the code box in the original post (thought it would make it easier to have all of it in one place.) The backend is Sharepoint. I'll try and open the form and update it manually. And I'll sniff around and see if there are other posts with issues around 2010 and Sharepoint since it works ok in 2007.
Dec 6 '11 #6
NeoPa
32,556 Recognized Expert Moderator MVP
You sound like a member who responds intelligently to posts. Always good news. Let me just suggest here that identifying lines of code is easier and more reliable using line numbers (EG. Line #14 etc).

PS. Updating the original post made sense I feel.
Dec 6 '11 #7
sceptar17
5 New Member
Line numbers it is, thanks for the reminder. (It was line #23 for what it's worth.)

Anyway, I believe the issue has been solved, although I don't completely understand why. I changed the form that is being updated to open as a datasheet instead of in form view and voila, works perfectly. I dug through the settings on the form and still can't figure out why the form view wasn't working.

So, I'll live to get in over my head another day. Thanks to both of you for your help and courtesy, very much appreciated.
Dec 6 '11 #8
NeoPa
32,556 Recognized Expert Moderator MVP
I'm pleased that you managed to resolve your issue.

We don't generally encourage members to award the Best Answer to one of their own posts though. There are some rare occasions when it makes sense, but not this one I'm afraid.
Dec 6 '11 #9
sceptar17
5 New Member
I thought perhaps it was a way to get the answer to the top of the question so folks didn't have to dig. Sorry about that. (It did seem a little egotistical at the time now that you mention it.)

Thanks again for your help.
Dec 6 '11 #10

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

Similar topics

5
by: R Duncan | last post by:
Hi, I'm considering moving a payroll application out of Microsoft Access to some web-based solution. It is getting way to big for Access and the system is growing unstable, so I'm learning PHP...
6
by: Robert | last post by:
Hello, Accessors What I would like to do is create a multi-record table update. I have a table and a form for it. I want to modify it so that there is a new field (textbox) (not bound to a...
1
by: Joe Bloggs | last post by:
Hello, I have a form linking two tables but they have one field that is shared called "device" I want to allow data input into one of the fields and hide the other (so I need it automatically...
1
by: =?Utf-8?B?Q2hhZCBU?= | last post by:
I am very new to asp.net (I know asp better) and have hit a road block. I have a master page that links to a content page. The purpose of the content page is to edit the database record. I have...
0
by: jessejames | last post by:
I need to update multiple record in my table(in PostgreSQL dbase).. here is my sample data user_id user_name display_name email_address 1 user1 BPI ...
3
by: barmatt80 | last post by:
I finally got my call to a stored procedure on our db2 to work. However i might have to change what the stored procedure does, if I cannot get it to work how we want. Which i would like to make it...
12
by: raamay | last post by:
Hi Experts, here i come again and wanna ask how we can perform record update in PHP & MySQL without passing the id in the URL for the $_GET method to be used in the processing page. I mean I have...
0
by: Lyu KingT | last post by:
hi, i need to control the right of a Office document in my Visual Studio Projects, so how to enable or disable the print, what abou edit, save..... i try to fellow the video How Do I: Hi-jack...
1
by: colsoft | last post by:
Please I want to know i how i can search for a specific record in a report and print that record without using the arrows at the bottom. Like show a dialog or use an input box to search through the...
1
dsatino
by: dsatino | last post by:
My company has recently been upgrading all operating systems to Windows 7 and all MS Office products to the 2010 version. I've managed to update/modify all code to run on both the .mdb and .accdb...
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
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
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,...
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
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.