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

I have an application that i am working on that has many userforms. at
the bottom of the userform there is one commandbutton, and i want all
the userforms to do the same procedure when that command button is
clicked.

here is the code:
Public Sub pg_finish()
Dim ctl As Control
Dim count As Integer
Dim fname As String

On Error Resume Next
fname = Environ("temp") & "\PG " & ActiveCell.Value & ".xls"
count = 3
ActiveCell.Offset(0, 1).Value = "sold"
For Each ctl In Me.Controls
If TypeName(ctl) = "ComboBox" Then
ActiveCell.Offset(0, count).Value = ctl.Name & ": " &
ctl.Value
count = count + 1
End If
Next ctl
ActiveCell.Offset(0, count).Value = "Total: " & TextBox1.Value
ActiveSheet.Copy
ActiveWorkbook.SaveAs fname
ActiveWorkbook.SendMail ", fname
ActiveWorkbook.ChangeFileAccess xlReadOnly
ActiveWorkbook.Close
Kill fname

Application.Workbooks("dk design
macro.xls").Worksheets("sheet1").Activate
count = 0
Unload Me
End Sub

the code was working fine, when it was written in the code window of
the userform, but i tried to move it to a module, so that all the
userforms could refer to it, now the line that reads "For Each ctl In
Me.Controls" isn't working. I understand that me won't work, because
the code is not in the form's code window. how can i make that
reference more generic, so that it will work here.

thanks for any help.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default userform controls

natanz,

Add an argument to the sub...
Public Sub pg_finish(ByRef objForm as Object)

When you call the sub supply the form as the argument...
Call pg_finish(Me)

Then use the objForm variable to replace all references to "me"
in the Public Sub code.

Jim Cone
San Francisco, USA


"natanz"
wrote in message
oups.com
I have an application that i am working on that has many userforms. at
the bottom of the userform there is one commandbutton, and i want all
the userforms to do the same procedure when that command button is
clicked.

here is the code:
Public Sub pg_finish()
Dim ctl As Control
Dim count As Integer
Dim fname As String

On Error Resume Next
fname = Environ("temp") & "\PG " & ActiveCell.Value & ".xls"
count = 3
ActiveCell.Offset(0, 1).Value = "sold"
For Each ctl In Me.Controls
If TypeName(ctl) = "ComboBox" Then
ActiveCell.Offset(0, count).Value = ctl.Name & ": " &
ctl.Value
count = count + 1
End If
Next ctl
ActiveCell.Offset(0, count).Value = "Total: " & TextBox1.Value
ActiveSheet.Copy
ActiveWorkbook.SaveAs fname
ActiveWorkbook.SendMail ", fname
ActiveWorkbook.ChangeFileAccess xlReadOnly
ActiveWorkbook.Close
Kill fname

Application.Workbooks("dk design
macro.xls").Worksheets("sheet1").Activate
count = 0
Unload Me
End Sub

the code was working fine, when it was written in the code window of
the userform, but i tried to move it to a module, so that all the
userforms could refer to it, now the line that reads "For Each ctl In
Me.Controls" isn't working. I understand that me won't work, because
the code is not in the form's code window. how can i make that
reference more generic, so that it will work here.
thanks for any help.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default userform controls


Hello Natanz,

You need to pass the UserForm's object reference to the module. I have
made the changes to code so you can copy and paste it.

EXAMPLE CALLING THE ROUTINE:
Call pg_finish (UserForm1)

Substitute the name of the userform for UserForm1 in the example. Do
not put the user form's name in quotes.


Code:
--------------------
Public Sub pg_finish(ByRef MyForm As UserForm)
Dim ctl As Control
Dim count As Integer
Dim fname As String

On Error Resume Next
fname = Environ("temp") & "\PG " & ActiveCell.Value & ".xls"
count = 3
ActiveCell.Offset(0, 1).Value = "sold"

For Each ctl In MyForm.Controls
If TypeName(ctl) = "ComboBox" Then
ActiveCell.Offset(0, count).Value = ctl.Name & ": " &
ctl.Value
count = count + 1
End If
Next ctl

ActiveCell.Offset(0, count).Value = "Total: " & TextBox1.Value
ActiveSheet.Copy
ActiveWorkbook.SaveAs fname
ActiveWorkbook.SendMail ", fname
ActiveWorkbook.ChangeFileAccess xlReadOnly
ActiveWorkbook.Close
Kill fname

Application.Workbooks("dk design
macro.xls").Worksheets("sheet1").Activate
count = 0

Unload MyForm

End Sub

--------------------

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=480768

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default userform controls

thanks for all your help. One problem. I am trying to pass the
userform, along with the values input into it by the user. This is
passing the userform, but the values have been lost. Can i do this?

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
Adding controls to userform ExcelMonkey[_190_] Excel Programming 3 February 25th 05 11:30 AM
Userform Controls Nigel Excel Programming 5 December 30th 04 01:49 PM
looping through userform controls JulieD Excel Programming 2 August 14th 04 02:13 PM
Help please with UserForm controls sa3214 Excel Programming 4 July 2nd 04 03:00 AM
Add controls to UserForm Vyyk Drago Excel Programming 3 August 26th 03 01:22 PM


All times are GMT +1. The time now is 07:50 PM.

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

About Us

"It's about Microsoft Excel"