Run-time error 365: Unable to unload within this context.
Need some help!
I use a little Procedure create_checkBox() that creates checkboxes in RunTime. And there is a Procedure RemvCheckbx() that removes those checkboxes.
Both procedures work just fine separately but, when I call RemvCheckbx() from create_checkBox() then, I get Run-time error 365: Unable to unload within this context.
Any help would be appreciated.
Al
Main Form code:
Option Explicit
Dim sINIFile As String
Dim clntType As String
Sub InitProgram()
Dim nCount As Integer
Dim i As Integer
Dim cCount As Integer
'Store the location of the INI file
sINIFile = App.Path & "\MYAPP.INI"
' Reset History on ini file
writeINI sINIFile, "FrameHistory", "qty", 0
writeINI sINIFile, "CheckBxHistory", "qty", 0
cCount = CInt(sGetINI(sINIFile, "Settings", "NumbofTypes", 0))
For i = 1 To cCount
combx_Clients.AddItem sGetINI(sINIFile, "Settings", "Type" & i, 0)
Next
' combx_Clients.Text = sGetINI(sINIFile, "Settings", "Type1", combx_Clients.List(0))
End Sub
Sub combx_Clients_Click()
' Dim clntType as String
Dim clntName As String
Dim i, qty As Integer
Dim mForm As Form
Call RemvCheckbx
clntType = combx_Clients.Text
qty = CInt(sGetINI(sINIFile, clntType, clntType & "Numb", 0))
Call create_checkBox(clntType, qty, frmMain)
Frame1.Caption = clntType
End Sub
Private Sub cmd_Exit_Click()
End
End Sub
Private Sub Command2_Click()
Call RemvCheckbx
End Sub
Private Sub Form_Load()
InitProgram
End Sub
Module code:
Option Explicit
Private ctlName As Control
Sub create_checkBox(cNames As String, cCount As Integer, mForm As Form)
Dim fLeft, fHight As Integer
Dim i, count As Integer
' Call RemvCheckbx
count = 1
fLeft = 200
With mForm
fHight = .Frame1.Height
For i = 1 To cCount
Set ctlName = .Controls.Add("vb.CheckBox", "chk" & i, .Frame1)
ctlName.Visible = True
If .Frame1.Height <= ((count + 1) * 300) Then
fLeft = fLeft + 1800
count = 1
End If
' ctlName.Move Left, Top, Height, With
ctlName.Move fLeft, count * 300, 1200, 250
ctlName.Caption = "Label " & i
count = count + 1
Next
End With
' Write History in ini file for the "removeprocedure"
writeINI App.Path & "\MYAPP.INI", "FrameHistory", "qty", Str(cCount)
writeINI App.Path & "\MYAPP.INI", "FrameHistory", "name", cNames
End Sub
Sub RemvCheckbx()
' Removes the controls created in RunTime
Dim i, qty As Integer
Dim cName As String
Dim sINIFile As String
sINIFile = App.Path & "\MYAPP.INI"
qty = CInt(sGetINI(sINIFile, "FrameHistory", "qty", 0))
cName = sGetINI(sINIFile, "FrameHistory", "name", 0)
If qty = 0 Then Exit Sub
For i = 1 To qty
frmMain.Controls.Remove "chk" & i
Next i
writeINI App.Path & "\MYAPP.INI", "FrameHistory", "qty", Str(0)
End Sub

