Re: Checkbox activating sub function
OK, I have changed your code somewhat. The problem was with how you were using the form. While segregating code is a good idea, skipping from the form to the modules, etc and using the same variable names defined several times was causing the form to think that one of your check boxes was always on, and the other was always off, because FEthernet was used for both boxes.
Also, I changed the directory structure so I could use it on my computer. You will need to change it back in your worksheet.
Here is the code:
Sheet12 private sub:
Private Sub BtnCreate_Click()
Call Generate
End Sub
frmstart code:
Private Sub BtnCancel_Click()
Unload Me
Cancel = True
Sheets("Macro").Select
End Sub
Private Sub BtnOK_Click()
If Len(TxtSite.Value) = "" Then Exit Sub
Site = TxtSite.Value
If OptFastEthernet.Value = True Then MMLType = "FastEthernet"
On Error Resume Next
MkDir "C:\Users\jbbrockman\Desktop\" & TxtSite.Value
'start FastEthernet command
If CkbScriptNodeB.Value = True Then
Open "C:\Users\jbbrockman\Desktop\" & FrmStart.TxtSite.Value & "\Add_NodeB.txt" For Output As 2
Print #2, "TEST 1"
Close 2
End If
If CkbScriptRNC.Value = True Then
Open "C:\Users\jbbrockman\Desktop\" & FrmStart.TxtSite.Value & "\Add_RNC.txt" For Output As 3
Print #3, "TEST 2"
Close 3
End If
Unload Me
Sheets("Macro").Select
End Sub
Private Sub OptFastEthernet_Click()
'start enable Fast Ethernet Script
CkbScriptNodeB.Enabled = True
CkbScriptRNC.Enabled = True
'end enable Fast Ethernet Script
End Sub
Private Sub UserForm_Initialize()
If MMLType = "FastEthernet" Then OptFastEthernet.Value = True
If MMLType = "FastEthernet" Then
CkbScriptNodeB.Enabled = True
CkbScriptRNC.Enabled = True
Else
CkbScriptNodeB.Enabled = False
CkbScriptRNC.Enabled = False
End If
If FEthernet1 = 1 Then CkbScriptNodeB.Value = True
If FEthernet2 = 2 Then CkbScriptRNC.Value = True
TxtSite.Value = Site
TxtSite.SetFocus
End Sub
Display More
principalmod code:
Public Cancel As Boolean
Public Site, MMLType, MacroWB, NewWorkbook As String
Public FEthernet1 As Integer
Sub Generate()
MacroWB = ActiveWorkbook.Name
MMLType = "Create"
E1Num = 2
FEthernet1 = 1
CallFrmStart:
Site = ""
Cancel = False
IncorrectSite = False
FrmStart.Show
If Cancel = True Then
Unload FrmStart
Exit Sub
End If
End Sub
Display More
FastEthernetmod was redundant at this point, so I deleted it.
forum.ozgrid.com/index.php?attachment/37418/ -- here is the workbook as well. Don't forget to change the directories back.
In summary, when using a button on a form, drive the actions within the button code. Don't reference back to a module that also uses the same variable.
Hope this helped. Sorry if I inadvertently deleted some functionality. You can add it back, just do it in line with the form.