How to fill textbox using the For...To...Next...

  • Thread starter Thread starter Dom.
  • Start date Start date
D

Dom.

Hello everyone,

I have a form and I need the controls to be filled
with dcount values. I have tried the following code but
that did not seem to work correctly.

'''begin code
Dim i as Integer
For i = 1 to 7
Me("txtQtrOne_Q" & i)= Dcount("SysID" & i,"myTable", _
"(Q)& i = 1)
Next i
'''end code

myTable contains Questions 1 - 7 and I want all those
question to be counted if the value is 1, otherwise ignore
it. The part that is not working properly is the Dcount
portion of it. I'm not that experience in VBA but i'm
learning, any sugestions.
 
You need some more quotes around the last bit:

"(Q)& i = 1)

should be more like

"(Q" & i & "=1)"

But you should be able to do this a lot easier by binding the form to a
recordsource ( a query ) extracting the data from your table. Then you dont
need any code at all to populate the textboxes.

--
Regards,

Adrian Jansen
J & K MicroSystems
Microcomputer solutions for industrial control
 
Thank you for your reply.

Your sugestion did indeed worked to perfection. Now, what
if I want to the criteria change? I tried substituting the
1 for i but it gave me an error that the automation i does
not exist.
 
If you want the "1" to be a user settable variable, eg taken from another
unbound textbox on your form, say we call it txtCriteria for example. Then
you code ( just the criteria bit, if all the rest works ):

"(Q" & i & "=" & me.txtCriteria & ")"

Do you see how this works ? You need the quotes to separate out the bits
which are literal strings, like the "Q", and & signs to concatenate these
with the things which have values, like the "i" and the me.txtCriteria.
Note the "me." - this is a reference to "the current form" without having to
specify the actual form name.

Once you learn the basics of this, you are well on the way to constructing
useful code.




--
Regards,

Adrian Jansen
J & K MicroSystems
Microcomputer solutions for industrial control
 
Back
Top