Looping Coding Issue

Pooks_35

Registered User.
Local time
Yesterday, 22:38
Joined
Mar 14, 2013
Messages
54
I need to create a loop for the following command to be completed 23 times. I'm new to the looping and I'm not sure how to write the code for this. I need to go through 23 fields (Time1, Time2, Time3,.....Time23). Can anyone help me with the coding to create the loop? Thanks!
Me.Time1.Visible = Me.Time1 <> "Other"
Me.Other1.Visible = Me.Time1 = "Other"
 
You can use a For/Next loop, using the counter in your code:

Me("Time" & x).Visible = Me("Time" & x) <> "Other"
 
Thanks, I'm still pretty new to writing code, how would the coding look with the timer? I've googled and searched this site, but I can't find the correct coding to pull it all together to function correctly.:banghead:
 
Really?

Code:
Dim x as Integer

For x = 1 to 23
  'your code here
Next x
 
I had that code in at one point, I did put it back in since you confirmed that was correct what I was using, but I get a Run-time error 438 when I try to run it. When I run the code in the Immediate windows I get Compile error: Next without For. I don't know what I am doing wrong with the coding.

Dim x As Integer
For x = 1 To 23
Me("Time" & x).Visible = Me("Time" & x) <> "Other"
Me("Other" & x).Visible = Me("Time" & x) = "Other"
Next x
 
What's the full code in the procedure? I don't see anything wrong with that bit.
 
Private Sub Detail1_Print(Cancel As Integer, PrintCount As Integer)
Dim x As Integer
For x = 1 To 23
Me("Time" & x).Visible = Me("Time" & x) <> "Other"
Me("Other" & x).Visible = Me("Time" & x) = "Other"
Next x
End Sub
 
Can you post the db here? I put that code into a procedure and it compiles fine.
 
Unfortunately, I can't as it is a large database that would take time to remove all the data that I would need to remove due to PII, it would take a lot of time to go through it.
 
I understand. I just noticed you said "when I run the code in the Immediate window". The code should be run by opening the report and seeing if it works, not from the Immediate window. By the way, I'd use the format event of the detail section, presuming you're using preview or print rather than report view.
 
You are correct, I was trying to run the report in Print Preview and I kept getting the Run Time 438 error. I did remove the parameter for ID (so I was running reports for all the individuals in the database and not just my test data), now I get type mismatch when I do that. I'm looking at a couple of different options to try and figure out why it is doing this. Thanks again though for all your help!
 
No problem; post back if you're still stuck. An option to taking stuff out of the actual db is exporting the relevant object(s) to a new db, and cleansing the data if appropriate.
 
Still stuck on this one. I can't get the code below to work:
Private Sub Detail1_Print(Cancel As Integer, PrintCount As Integer)
Dim x As Integer
For x = 1 To 23
Me("Time" & x).Visible = Me("Time" & x) <> "Other"
Me("Other" & x).Visible = Me("Time" & x) = "Other"
Next x
End Sub

The bolded line is highlighed in the Run-time Error 438: Object doesn't support this property or method.

I have a feeling it has somthing to do with the fact that the x is "As Integer" when the Time is actually a text field. Any suggestions on how to fix this error.
thanks!
 
These are textboxes? What is the value of x when it fails?
 
The text boxes are named Time1, Time2, Time3, etc through Time23. The x represented is the number in the label (Timex).
 
I meant are they text boxes rather than labels? Regarding the x, I'm trying to determine when it's failing, on the first pass through or in a later loop.
 
They are text boxes, not labels. sorry about that!
 
I understand the db has private content, but can you post just that report or something? This would be easier if I can play with it.
 
Sorry it took so long to respond. I had to do some work to remove any information except just what you needed! Here it is.
 

Attachments

The only control with that name is the first one. The code stops at the second, because there is no control named Time2. The rest are all comboxxx.
 

Users who are viewing this thread

Back
Top Bottom