473,499 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loop on a form

82 New Member
Hi, I hope someone can help me. I have the following set on the On Current of a form's property and it doesn't loop. I don't see anything wrong with the code. Thanks in advance.
Expand|Select|Wrap|Line Numbers
  1. Set rst = Me.RecordsetClone
  2. Set db = CurrentDb
  3.  
  4.  
  5. If rst.RecordCount = 0 Then Exit Sub
  6.  
  7. rst.MoveFirst
  8. Do While Not rst.EOF
  9. rst.Edit
  10.  
  11.  
  12. If Me.StartDate >= DateAdd("yyyy", -1, Date) Then Me.Eligible = "<12Months" Else Me.Eligible = "Eligible"
  13.  
  14. rst.Update
  15.  
  16. rst.MoveNext 
  17. Loop
  18.  
  19.  
  20. rst.Close
  21. Set rst = Nothing
  22. Set db = Nothing
  23.  
  24. Close
  25.  
May 10 '13 #1
9 1058
NeoPa
32,557 Recognized Expert Moderator MVP
Line #12 uses multi-line If syntax on a single line.

Please see Before Posting (VBA or SQL) Code.
May 10 '13 #2
barbarao
82 New Member
I don't know how to fix that as I didn't know it was wrong. Can you help me? Thanks.
May 10 '13 #3
NeoPa
32,557 Recognized Expert Moderator MVP
To fix your code you would use :
Expand|Select|Wrap|Line Numbers
  1. If Me.StartDate >= DateAdd("yyyy", -1, Date) Then
  2.     Me.Eligible = "<12Months"
  3. Else
  4.     Me.Eligible = "Eligible"
  5. End If
However, for such a requirement the following code may prove more sensible :
Expand|Select|Wrap|Line Numbers
  1. Me.Eligible = IIf(Me.StartDate >= DateAdd("yyyy", -1, Date), "<12Months", "Eligible")
PS. That's not the response I would have expected, had you read the linked page. Please make sure you do before posting again.
-Moderator.
May 10 '13 #4
barbarao
82 New Member
I tried both of those suggestions and the loop is not looping with either one. I did read the linked page; I'm still learning this stuff which is why I am reaching out when I don't understand something that I have read.
May 10 '13 #5
Rabbit
12,516 Recognized Expert Moderator MVP
Why are you doing it this way instead of using an update query?
May 10 '13 #6
barbarao
82 New Member
That just might work. I will try that and let you know. Thanks.
May 10 '13 #7
barbarao
82 New Member
thanks so much. you are always very helpful.
May 10 '13 #8
Rabbit
12,516 Recognized Expert Moderator MVP
Glad to help.
May 10 '13 #9
NeoPa
32,557 Recognized Expert Moderator MVP
BarbaraO:
I tried both of those suggestions and the loop is not looping with either one.
I can't see why that would be if you put either of my snippets of code in place of line #12.

I would certainly recommend going for an update query if the record source is predictable. Sometimes though, forms have a record source that is complex and hard to reproduce in a query without complicated parsing of strings.

If you wish to proceed on the original question then please post your latest compiled and tested code (which should include the whole of the procedure) and explain exactly what you're seeing as results, with emphasis on describing any problems clearly.
May 10 '13 #10

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

Similar topics

0
2544
by: Kingdom | last post by:
I Need some serious help here. strugling novis with ASP and javascript any help would be greatly appreciated The script below does exactly what I want it to do for each product on the two passes...
1
1514
by: Scott Navarre | last post by:
Hello, I was wondering if there is a way (through JavaScript) to find out which of the form's elements currently has focus -- like returning an element name or index number... Thanks in...
22
2191
by: Jan Richter | last post by:
Hi there, the Code below shows DJBs own implementation of strlen (str_len): unsigned int str_len(char *s) { register char *t; t = s; for (;;) { if (!*t) return t - s; ++t;
10
1723
by: peter hansen | last post by:
I tried a couple of weeks ago but I'll try again :D I old VB6-days it was possible to unload a form bu using the Unload(Form) command. I have tried the Close-function but it'll unload the entire...
2
2030
by: | last post by:
While I can extract the option value from the following: <Select name='Keystring' MULTIPLE> <option value='1' name='status'>Pending</option> ..... </select> I cannot seem to extract the...
18
3686
by: Derek Basch | last post by:
What is the best way to count nested loop iterations? I can only figure to use an index but that seems kludgy. index = 0 for animal in zoo: for color in animal: index += 1 Thanks, Derek...
7
9135
by: ayesha | last post by:
hi i am beginner in java and i need help with programining ,Please if you could suggest me some sites where i can see some solved examples of codes as well as i need code for following ********...
1
4941
by: mr k | last post by:
Hi, I wanted to use mail merge with forms but Text form fields are not retained during mail merge in Word, I got the code from Microsoft but it doesn't remember the text form field options such as...
4
1285
by: touf | last post by:
Hi, I need to change the labels of all controls in a form, for this I wrote a code that loop form.controls and set the text property (to control.name for example). The problem is that some...
4
1804
vikas251074
by: vikas251074 | last post by:
Loop runs indefinite times. suppose v_router = 5 is entered by user, then following code runs indefinite times i.e. record is inserted indefinite times though each have different i and v_ip_address....
0
7178
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,...
1
6899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7390
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
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
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
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
302
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...

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.