-
Run-time error 365: Unable to unload within this context.
Hi everybody,
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
Code:
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
Last edited by Phil Weber; 12-31-2005 at 08:14 AM.
-
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
old thread, i know, but Mine does not make sense. this same procedure was formerly working, and now it stopped and gives me this error.
as a user changes the database to look through, a set of conditions is loaded in indexed textboxes.
when a new database is selected and the process starts again, i'm trying to unload the old text boxes so i can load new ones.
the load saved conditions sub is in a cmb box event, but is not related to that combobox.
is there a way around this to keep from getting this error?
when could i unload these boxes before loading new ones?
Code:
Public Sub LoadSavedConditions(rs As ADODB.Recordset, frm As Form)
'========================================================================
'''''''''Loads current values from db into dynamically loading textboxes
'========================================================================
Dim query As String
Dim count, row, col, intDown, top, left, moveleft, leftstart, startCol As Integer
UnloadDynTxtBoxes frm
For count = 1 To frm.Chk1().ubound Step 1
Unload frm.Chk1(count)
Next count
'............
End Sub
Code:
Public Sub UnloadDynTxtBoxes(thisFrm As Form)
'=================================================================
'unloads dynamically created Indexed textboxes from form
'=================================================================
Dim count As Integer
With thisFrm
For count = 1 To .Text1.ubound Step 1
Unload frmSpec.Text1(count)
Next count
End With
End Sub
Last edited by chupacabra; 04-17-2007 at 02:14 PM.
-Jon
Visual Basic 6.0
Microsoft Access 2003
-
there are meny situations where you cannot unload objects, one is in the Click event of a ComboBox
http://msdn2.microsoft.com/en-us/lib...62(VS.60).aspx
the solution is to remove the unload from the event. in case, you can add a timer in your form, in the click event start the timer, and remove the objects in the Timer event (and remember to stop the Timer)
"There are two ways to write error-free programs. Only the third one works."
Unknown
-
 Originally Posted by mstraf
there are meny situations where you cannot unload objects, one is in the Click event of a ComboBox
http://msdn2.microsoft.com/en-us/lib...62(VS.60).aspx
the solution is to remove the unload from the event. in case, you can add a timer in your form, in the click event start the timer, and remove the objects in the Timer event (and remember to stop the Timer)
hmm...that's a good idea.
would that not still be a part of the click event, because it falls under it?
or is it acceptable because it's part of a new event and then doesnt fall under the first event.
I'll try the timer idea tomorrow, thanks!
-Jon
Visual Basic 6.0
Microsoft Access 2003
Similar Threads
-
By dhaya in forum Database
Replies: 11
Last Post: 08-25-2003, 05:24 PM
-
By Tim Johnson in forum VB Classic
Replies: 4
Last Post: 09-12-2002, 09:27 AM
-
By SAM in forum VB Classic
Replies: 1
Last Post: 02-27-2002, 11:46 AM
-
By DH in forum VB Classic
Replies: 1
Last Post: 11-07-2001, 02:43 PM
-
By Lytech in forum VB Classic
Replies: 4
Last Post: 10-20-2000, 12:41 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|