ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   This is easy for you people! (https://www.excelbanter.com/excel-programming/333533-easy-you-people.html)

Michael

This is easy for you people!
 
I have a sheet1 with a lot of numbers and Text, in the module to this sheet i
have a VB code. Depending of what choices the user makes a new form appears.
The form has 3 CmdButtons, called Ok, Next, Cancel. It's like this:

If
ActiveSheet.Range("e" & EnviromentRow).Value="b6"
then

Beep
Load FrmNewInput
FrmNewInput.Show

The form code is like this:
(The code for the Ok button)

Private Sub CmdOk_Click()
''missing something''''
Me.Hide
End Sub

''''And then it should "go back" to the module and something like this:

If FrmNewInput.CmdCancel = True Then '''''If the user press the
cancel button
Exit Sub
ElseIf FrmNewInput.CmdOk = True Then
msgbox
Else FrmNewInput.CmdNext = True then
msgbox
End If

This is not correct i know that, but what is wrong?



keepITcool

This is easy for you people!
 

for more control use a variable of class frmNewInput
similar to..

'in a module
Dim uf1 As UserForm1 'use a module level variable.

Sub FormLoader()
If uf1 Is Nothing Then
Set uf1 = New UserForm1
End If
uf1.Show
MsgBox uf1.lngExit & vbLf & uf1.TextBox1 & vbLf & uf1.TextBox2
if uf1.lngExit = -1 then set uf1 = nothing
End Sub


'in a form of class UserForm1
'holds 2 textboxes and 2 commandbuttons
Option Explicit
Public lngExit As Long

Private Sub CommandButton1_Click()
lngExit = 1
Me.Hide
End Sub

Private Sub CommandButton2_Click()
lngExit = -1
Unload Me
End Sub

Private Sub UserForm_Initialize()
Me.TextBox1 = "initial value"
Me.TextBox2 = "initial value"
End Sub


HTH..


--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Michael wrote :

I have a sheet1 with a lot of numbers and Text, in the module to this
sheet i have a VB code. Depending of what choices the user makes a
new form appears. The form has 3 CmdButtons, called Ok, Next,
Cancel. It's like this:

If
ActiveSheet.Range("e" & EnviromentRow).Value="b6"
then

Beep
Load FrmNewInput
FrmNewInput.Show

The form code is like this:
(The code for the Ok button)

Private Sub CmdOk_Click()
''missing something''''
Me.Hide
End Sub

''''And then it should "go back" to the module and something like
this:

If FrmNewInput.CmdCancel = True Then '''''If the user press
the cancel button
Exit Sub
ElseIf FrmNewInput.CmdOk = True Then
msgbox
Else FrmNewInput.CmdNext = True then
msgbox
End If

This is not correct i know that, but what is wrong?


Rich_z[_12_]

This is easy for you people!
 

Have a look at this:


Code
-------------------

If ActiveSheet.Range("e" & EnviromentRow).Address="$B$6" then '* I've put address here but if the value is B6 then put it back
Beep
Load FrmNewInput
FrmNewInput.Show
End If

Select Case FrmNewInput.Button_Code
Case FrmNewInput.Cancel
Code here for canceling
Case FrmNewInput.Ok
Code here for ok button
Case FrmNewInput.CmdNext
Code here for next
End Select

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


In your form at module level:


Code
-------------------

Public Const Cancel = 1
Public Const Ok = 2
Public Const CmdNext = 3
'*
Public Button_Code as Integer

Private Sub CmdOk_Click()
Button_Code = Ok
Me.Hide
End Sub

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



Regards

Ric

--
Rich_
-----------------------------------------------------------------------
Rich_z's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread.php?threadid=38426


Michael

This is easy for you people!
 
Thanks.
It worked like i hoped.

Thank you again:-)
--
Nil Satis Nisi Optimum


"keepITcool" wrote:


for more control use a variable of class frmNewInput
similar to..

'in a module
Dim uf1 As UserForm1 'use a module level variable.

Sub FormLoader()
If uf1 Is Nothing Then
Set uf1 = New UserForm1
End If
uf1.Show
MsgBox uf1.lngExit & vbLf & uf1.TextBox1 & vbLf & uf1.TextBox2
if uf1.lngExit = -1 then set uf1 = nothing
End Sub


'in a form of class UserForm1
'holds 2 textboxes and 2 commandbuttons
Option Explicit
Public lngExit As Long

Private Sub CommandButton1_Click()
lngExit = 1
Me.Hide
End Sub

Private Sub CommandButton2_Click()
lngExit = -1
Unload Me
End Sub

Private Sub UserForm_Initialize()
Me.TextBox1 = "initial value"
Me.TextBox2 = "initial value"
End Sub


HTH..


--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Michael wrote :

I have a sheet1 with a lot of numbers and Text, in the module to this
sheet i have a VB code. Depending of what choices the user makes a
new form appears. The form has 3 CmdButtons, called Ok, Next,
Cancel. It's like this:

If
ActiveSheet.Range("e" & EnviromentRow).Value="b6"
then

Beep
Load FrmNewInput
FrmNewInput.Show

The form code is like this:
(The code for the Ok button)

Private Sub CmdOk_Click()
''missing something''''
Me.Hide
End Sub

''''And then it should "go back" to the module and something like
this:

If FrmNewInput.CmdCancel = True Then '''''If the user press
the cancel button
Exit Sub
ElseIf FrmNewInput.CmdOk = True Then
msgbox
Else FrmNewInput.CmdNext = True then
msgbox
End If

This is not correct i know that, but what is wrong?




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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com