Hi,
I've come across an odd issue that isn't clear so I'd like input from someone to point me in the right direction if possible please. It's probably easy and I've missed something fundamental!
I want to design an unbound form that has around 60 rows of three fields. At this point I'm not connecting it to a database table.
On each row, one field is a text input, the next two are checkboxes like this:
<Field1> <Checkbox1> <Checkbox2>
Assuming I have 60 rows of this, I'm trying to find an easy way to populate each set of say, <Checkbox1> with True or False (via a button) but I need to code it.
I can easily do this one by one by addressing each checkbox field explicitly and using SetFocus and <FieldName> = False (or True). It works of course but it's messy and will create a huge amount of code for the 60 rows. I don't want to do that. I want to do it in a loop.
Each <Checkbox1> is called T_Inx Where x is the row number, so Row1 it's called T_In1, Row2 it's called T_In2 etc...
I'm trying to use a loop to pass these values but I have the syntax very wrong as I'm very new to Access.
Here's the general simplified idea of what I'm trying to do:
Dim T as Integer
Dim LBL as String
' Reset the string variable
LBL = ""
T=1
' Just do 5 rows for now
For T = 1 to 5
LBL = "T_In" & T
' This pieces together the field name to reference where to put the field value
' Now see below...
Exit For
This will effectively generate a string (LBL) of "T_INx" for each iteration where x is the value of integer T. So, on each run of the loop we get a different value of x: T_In1, T_In2, T_In3, T_In4, T_In5 etc. This works ok.
Now I want to pass a value of FALSE (or TRUE) to the relevant field (checkbox) each time the loop increments.
So first pass the string LBL is "T_In1" = False, pass 2 "T_In2" = False etc etc.
Form is called just "InputForm"
I'm trying to add code similar to below into the loop to actually populate the fields on each iteration:
Forms!InputForm!LBL.SetFocus
Forms!InputForm!LBL = False
or
LBL.SetFocus
LBL = False
' Now increment the loop and do it again.
However, the Forms!InputForm!LBL.Setfocus (or the direct method) is not correct syntax as it won't pick up the string variable "LBL" and insert it into the SetFocus command as this part of the code string needs to be an absolute value.
I know I'm giving it incorrect code (that is obvious) but "logically", it's what I want to do.
So how do I do this? Is there a different piece of code I can use to pick up the string variable and update the field one by one in the loop?
It seems an obvious workflow but I can't work out what I need to do to address and pass the values... The syntax is weird.
What do you think? I hope I've explained it clearly!
I've come across an odd issue that isn't clear so I'd like input from someone to point me in the right direction if possible please. It's probably easy and I've missed something fundamental!
I want to design an unbound form that has around 60 rows of three fields. At this point I'm not connecting it to a database table.
On each row, one field is a text input, the next two are checkboxes like this:
<Field1> <Checkbox1> <Checkbox2>
Assuming I have 60 rows of this, I'm trying to find an easy way to populate each set of say, <Checkbox1> with True or False (via a button) but I need to code it.
I can easily do this one by one by addressing each checkbox field explicitly and using SetFocus and <FieldName> = False (or True). It works of course but it's messy and will create a huge amount of code for the 60 rows. I don't want to do that. I want to do it in a loop.
Each <Checkbox1> is called T_Inx Where x is the row number, so Row1 it's called T_In1, Row2 it's called T_In2 etc...
I'm trying to use a loop to pass these values but I have the syntax very wrong as I'm very new to Access.
Here's the general simplified idea of what I'm trying to do:
Dim T as Integer
Dim LBL as String
' Reset the string variable
LBL = ""
T=1
' Just do 5 rows for now
For T = 1 to 5
LBL = "T_In" & T
' This pieces together the field name to reference where to put the field value
' Now see below...
Exit For
This will effectively generate a string (LBL) of "T_INx" for each iteration where x is the value of integer T. So, on each run of the loop we get a different value of x: T_In1, T_In2, T_In3, T_In4, T_In5 etc. This works ok.
Now I want to pass a value of FALSE (or TRUE) to the relevant field (checkbox) each time the loop increments.
So first pass the string LBL is "T_In1" = False, pass 2 "T_In2" = False etc etc.
Form is called just "InputForm"
I'm trying to add code similar to below into the loop to actually populate the fields on each iteration:
Forms!InputForm!LBL.SetFocus
Forms!InputForm!LBL = False
or
LBL.SetFocus
LBL = False
' Now increment the loop and do it again.
However, the Forms!InputForm!LBL.Setfocus (or the direct method) is not correct syntax as it won't pick up the string variable "LBL" and insert it into the SetFocus command as this part of the code string needs to be an absolute value.
I know I'm giving it incorrect code (that is obvious) but "logically", it's what I want to do.
So how do I do this? Is there a different piece of code I can use to pick up the string variable and update the field one by one in the loop?
It seems an obvious workflow but I can't work out what I need to do to address and pass the values... The syntax is weird.
What do you think? I hope I've explained it clearly!