If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > loop control issue

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-27-09, 11:35
lulu1018 lulu1018 is offline
Registered User
 
Join Date: May 2009
Posts: 1
loop control issue

Ive been trying to loop checkboxes with textboxes in vba excel. If chk1 is checked then txt 1 is enabled that will allow the user to input a value. The final step is to create a string with chk1 caption with txt value. the checkboxes code works as well as the enable code however ive been unsuccessful with looping the textboxes
Private Sub chk2_Click()
txt2.Enabled = chk2
End Sub
Private Sub chk4_Click()
txt4.Enabled = chk4
End Sub
Private Sub chk1_Click()
txt1.Enabled = chk1
End Sub

Private Sub cmdAdd_Click()

Dim chk As Control
Dim Aux As String
Dim TB As String
Dim b As Integer

For b = 1 To 19
TB = frmLogBook.Controls("txt" & i).Value
Next b


For Each chk In frmLogBook.Controls
If TypeName(chk) = "CheckBox" Then
If chk.Object.GroupName = "auxiliary" Then
If chk.Value = True Then
Aux = chk.Caption & " " & TB & vbNewLine
End If
End If
End If
Next chk

Can anybody help??

Last edited by lulu1018; 05-27-09 at 11:43.
Reply With Quote
  #2 (permalink)  
Old 05-27-09, 23:23
Ax238 Ax238 is offline
Registered User
 
Join Date: May 2009
Posts: 257
I see a couple problems with the following code:
Code:
For b = 1 To 19
TB = frmLogBook.Controls("txt" & i).Value
Next b
First, you are looping on a variable "b", but you are using a variable "i" to get the textbox name. Second, all this logic will do, if it were to work, would be to continuously set the "TB" variable over and over again (19x) without doing anything with it.

You probably want to do something similar to the following:
Code:
For b = 1 To 19
	TB = frmLogBook.Controls("txt" & b).Value

	For Each chk In frmLogBook.Controls
		If TypeName(chk) = "CheckBox"
			If chk.Object.GroupName = "auxiliary" Then
				If chk.Value = True Then
					Aux = chk.Caption & " " & TB & vbNewLine
				End If
			End If
		End If
	Next chk
Next b
You may still have a problem with the following statement, unless you do something with it later, since it just resets the string over and over again:
Code:
Aux = chk.Caption & " " & TB & vbNewLine
Regards,

Ax
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On