Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 113
Default UserForm QueryClose

I have a fairly complex UserFrom called UF0_QCP and need to save it's data in
the workbook for which it was used (so that I can reinitialise later with the
last-used data. I have tried the following pair of subs but no msgbox from
either. What am I missing please (don't say the whole concept!)? Regards,
Brett


Private Sub UF0_QCP_QueryClose(Cancel As Integer, CloseMode As Integer)
MsgBox "QueryClose"
If CloseMode < 2 Then
Dim rw As Integer, cl As Integer
rw = Range("QCP.memory").Row + 1: cl = Range("QCP.memory").Column
For Each Control In UF0_QCP.Controls
On Error Resume Next
With Sheets("LAUNCHPAD")
.Cells(rw, cl) = Control.Name: .Cells(rw, cl + 2) =
Control.Caption: .Cells(rw, cl + 4) = Control.Value
.Cells(rw, cl + 6) = Control.Enabled: .Cells(rw, cl + 7) =
Control.Visible
.Cells(rw, cl + 8) = Control.Top: .Cells(rw, cl + 9) =
Control.Left
End With
rw = rw + 1: On Error GoTo 0
Next Control
Sheets("LAUNCHPAD").Range("QCP.memory") = True
End If
End Sub

AND FOR INITIALIZING;
Private Sub UF0_QCP_Initialize()
MsgBox "Initialize"
If Sheets("LAUNCHPAD").Range("QCP.memory") = True Then
Dim rw As Integer, cl As Integer
rw = Sheets("LAUNCHPAD").Range("QCP.memory").Row + 1: cl =
Sheets("LAUNCHPAD").Range("QCP.memory").Column
For Each Control In UF0_QCP.Controls
On Error Resume Next
With Sheets("LAUNCHPAD")
Control.Name = .Cells(rw, cl): Control.Caption =
..Cells(rw, cl + 2): Control.Value = .Cells(rw, cl + 4)
Control.Enabled = .Cells(rw, cl + 6): Control.Visible =
..Cells(rw, cl + 7)
Control.Top = .Cells(rw, cl + 8): Control.Left =
..Cells(rw, cl + 9)
End With
rw = rw + 1: On Error GoTo 0
Next Control
Sheets("LAUNCHPAD").Range("QCP.memory") = False
End If
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default UserForm QueryClose

Hi Brett,

Try nameing the subs as follows:-

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)

Assuming that you have the code in the userform code module, you don't use
the userform name.

The only events you can have are those that get created when you select the
userform from the dropdown at the top left of the VBA editor and then select
the event name from the top right dropdown. The subs then get created with
their correct name.

--
Regards,

OssieMac


"Brett" wrote:

I have a fairly complex UserFrom called UF0_QCP and need to save it's data in
the workbook for which it was used (so that I can reinitialise later with the
last-used data. I have tried the following pair of subs but no msgbox from
either. What am I missing please (don't say the whole concept!)? Regards,
Brett


Private Sub UF0_QCP_QueryClose(Cancel As Integer, CloseMode As Integer)
MsgBox "QueryClose"
If CloseMode < 2 Then
Dim rw As Integer, cl As Integer
rw = Range("QCP.memory").Row + 1: cl = Range("QCP.memory").Column
For Each Control In UF0_QCP.Controls
On Error Resume Next
With Sheets("LAUNCHPAD")
.Cells(rw, cl) = Control.Name: .Cells(rw, cl + 2) =
Control.Caption: .Cells(rw, cl + 4) = Control.Value
.Cells(rw, cl + 6) = Control.Enabled: .Cells(rw, cl + 7) =
Control.Visible
.Cells(rw, cl + 8) = Control.Top: .Cells(rw, cl + 9) =
Control.Left
End With
rw = rw + 1: On Error GoTo 0
Next Control
Sheets("LAUNCHPAD").Range("QCP.memory") = True
End If
End Sub

AND FOR INITIALIZING;
Private Sub UF0_QCP_Initialize()
MsgBox "Initialize"
If Sheets("LAUNCHPAD").Range("QCP.memory") = True Then
Dim rw As Integer, cl As Integer
rw = Sheets("LAUNCHPAD").Range("QCP.memory").Row + 1: cl =
Sheets("LAUNCHPAD").Range("QCP.memory").Column
For Each Control In UF0_QCP.Controls
On Error Resume Next
With Sheets("LAUNCHPAD")
Control.Name = .Cells(rw, cl): Control.Caption =
.Cells(rw, cl + 2): Control.Value = .Cells(rw, cl + 4)
Control.Enabled = .Cells(rw, cl + 6): Control.Visible =
.Cells(rw, cl + 7)
Control.Top = .Cells(rw, cl + 8): Control.Left =
.Cells(rw, cl + 9)
End With
rw = rw + 1: On Error GoTo 0
Next Control
Sheets("LAUNCHPAD").Range("QCP.memory") = False
End If
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 113
Default UserForm QueryClose

Hi Ossie, nice time of year eh? You know there are times when I'm far to
clever for my own good. I had actually done exactly as you described, but
thinking that I'm half smart I changed the USERFORM to UF0_QCP in the
procedure names (because that's what you do with these things, right?).
********. It works perfectly now. Thanks for the tip. Brett

"OssieMac" wrote:

Hi Brett,

Try nameing the subs as follows:-

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)

Assuming that you have the code in the userform code module, you don't use
the userform name.

The only events you can have are those that get created when you select the
userform from the dropdown at the top left of the VBA editor and then select
the event name from the top right dropdown. The subs then get created with
their correct name.

--
Regards,

OssieMac


"Brett" wrote:

I have a fairly complex UserFrom called UF0_QCP and need to save it's data in
the workbook for which it was used (so that I can reinitialise later with the
last-used data. I have tried the following pair of subs but no msgbox from
either. What am I missing please (don't say the whole concept!)? Regards,
Brett


Private Sub UF0_QCP_QueryClose(Cancel As Integer, CloseMode As Integer)
MsgBox "QueryClose"
If CloseMode < 2 Then
Dim rw As Integer, cl As Integer
rw = Range("QCP.memory").Row + 1: cl = Range("QCP.memory").Column
For Each Control In UF0_QCP.Controls
On Error Resume Next
With Sheets("LAUNCHPAD")
.Cells(rw, cl) = Control.Name: .Cells(rw, cl + 2) =
Control.Caption: .Cells(rw, cl + 4) = Control.Value
.Cells(rw, cl + 6) = Control.Enabled: .Cells(rw, cl + 7) =
Control.Visible
.Cells(rw, cl + 8) = Control.Top: .Cells(rw, cl + 9) =
Control.Left
End With
rw = rw + 1: On Error GoTo 0
Next Control
Sheets("LAUNCHPAD").Range("QCP.memory") = True
End If
End Sub

AND FOR INITIALIZING;
Private Sub UF0_QCP_Initialize()
MsgBox "Initialize"
If Sheets("LAUNCHPAD").Range("QCP.memory") = True Then
Dim rw As Integer, cl As Integer
rw = Sheets("LAUNCHPAD").Range("QCP.memory").Row + 1: cl =
Sheets("LAUNCHPAD").Range("QCP.memory").Column
For Each Control In UF0_QCP.Controls
On Error Resume Next
With Sheets("LAUNCHPAD")
Control.Name = .Cells(rw, cl): Control.Caption =
.Cells(rw, cl + 2): Control.Value = .Cells(rw, cl + 4)
Control.Enabled = .Cells(rw, cl + 6): Control.Visible =
.Cells(rw, cl + 7)
Control.Top = .Cells(rw, cl + 8): Control.Left =
.Cells(rw, cl + 9)
End With
rw = rw + 1: On Error GoTo 0
Next Control
Sheets("LAUNCHPAD").Range("QCP.memory") = False
End If
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
QueryClose problem Keith74 Excel Programming 4 October 2nd 07 03:04 PM
Userform Queryclose and Unload problem Dave Ramage Excel Programming 3 March 8th 07 07:39 PM
Is there an easy Copy/Paste of a Userform ? (Entire Userform Including tx & cbx's) Corey Excel Programming 2 January 9th 07 01:01 PM
Looping procedure calls userform; how to exit loop (via userform button)? KR Excel Programming 6 July 27th 05 12:57 PM
Activating userform and filling it with data form row where userform is activate Marthijn Beusekom via OfficeKB.com[_2_] Excel Programming 3 May 6th 05 05:44 PM


All times are GMT +1. The time now is 12:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"