Variable name?

  • Thread starter Thread starter Garry Jones
  • Start date Start date
G

Garry Jones

I have 30 text boxes that I want to send to a function called Chknow. I
want to use a loop but do not know the syntax to refer to each box in
turn.

This is what I am trying, it can't find field.
----------------------------------------------------
Private Sub Form_Current()
Dim boxnum As Variant
boxnum = 1
Do While boxnum < 31
Chknow ["distans" & boxnum]
boxnum = boxnum + 1
Loop
End Sub
----------------------------------------------------
The textboxes are distans1, distans2, distans3, etc....

How do I add the number in each field in turn using code similar to my
loop?

Very happy for any help.

Garry Jones
Sweden
 
You are close, Garry,


Private Sub Form_Current()
Dim boxnum As Variant
boxnum = 1
Do While boxnum < 31
Chknow Me.Controls("distans" & boxnum)
boxnum = boxnum + 1
Loop
End Sub
 
What does the function CheckNow do? I think the problem you are having is
that CheckNow is performing something that references a control object rather
than a string varialbe. You might try this construct:

Private Sub Form_Current()
Dim ctl As Control
For Each ctl In Forms!frmattributetable.Controls
If ctl.ControlType = acCheckBox and Left(ctl.Name, 7) = "distans" Then
ChkNow(ctl)
End If
Next

End Sub

If all you are doing is making the check boxes checked (or unchecked) you
can replace the call to ChkNow with
ctl = True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Calculate Total Books 4
Different way to Autofill previous record 1
Cancel Exit on duplicate 2
Reduce Code 4
Allow Edits 1
PowerPoint Shuffle (swap) objects on PPT slides with the same name only 0
Edit field 2
Hyperlink Edit 3

Back
Top