Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default Variable not seen

I cannot work out why the variable oStyle is not seen by the message forms
cmdOkNo_Click procedure. Should be simple but I've gone blank:

From a form I call a custom message box form which can have a combination of
Yes, No, Cancel or OK cmdbuttons. However I use only 3 buttons by switching
No and Ok on the same button. The messaging and configuring of the message
box is done in a module:

Public Function oMsgBox1(oStyle As String, oNumPrompts As Long, Prompt1 As
String, Prompt2 As String, Prompt3 As String, Prompt4 As String, Title As
String)

.code

End Function

The oStyle string can be OK or YNC or YN

oStyle, boMsgYes, boMsgNo, and boMsgCancel are declared globally elsewhere.

In the message form code I have:

Private Sub cmdOkNo_Click()
If oStyle = "YN" Or oStyle = "YNC" Then ''' oStyle remains ""
boMsgNo = True
End If
other stuff
End Sub

Private Sub cmdYes_Click()
boMsgYes = True
other stuff
End Sub

Private Sub cmdCancel_Click()
boMsgCancel = True
other stuff
End Sub

T.I.A.

Geoff

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 533
Default Variable not seen

oStyle, boMsgYes, boMsgNo, and boMsgCancel are declared globally
elsewhere.


Maybe so but your function declares a local set of variables with the same
names:

Function oMsgBox1(oStyle As String, oNumPrompts As Long, Prompt1 As
String, Prompt2 As String, Prompt3 As String, Prompt4 As String, Title As
String)


You can go two ways at least-

1. Set the global values before calling Function oMsgBox1 and pass nothing
to it.
2. Set global versions of the local variables in the function:

Function oMsgBox1(...)
PuboStyle=oStyle

Btw, if your Function oMsgBox1 returns nothing, as it appears, it shouldn't
be a function. Make it a Sub.

--
Jim
"Geoff" wrote in message
...
|I cannot work out why the variable oStyle is not 'seen' by the message form's
| cmdOkNo_Click procedure. Should be simple but I've gone blank:
|
| From a form I call a custom message box form which can have a combination
of
| Yes, No, Cancel or OK cmdbuttons. However I use only 3 buttons by
switching
| No and Ok on the same button. The messaging and configuring of the message
| box is done in a module:
|
| Public Function oMsgBox1(oStyle As String, oNumPrompts As Long, Prompt1 As
| String, Prompt2 As String, Prompt3 As String, Prompt4 As String, Title As
| String)
|
| ..code
|
| End Function
|
| The oStyle string can be "OK" or "YNC" or "YN"
|
| oStyle, boMsgYes, boMsgNo, and boMsgCancel are declared globally
elsewhere.
|
| In the message form code I have:
|
| Private Sub cmdOkNo_Click()
| If oStyle = "YN" Or oStyle = "YNC" Then ''' oStyle remains ""
| boMsgNo = True
| End If
| other stuff
| End Sub
|
| Private Sub cmdYes_Click()
| boMsgYes = True
| other stuff
| End Sub
|
| Private Sub cmdCancel_Click()
| boMsgCancel = True
| other stuff
| End Sub
|
| T.I.A.
|
| Geoff
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Variable not seen

If oStyle is a global variable, why is it also an argument to oMsgBox?

What does oMsgBox do?

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Geoff" wrote in message
...
I cannot work out why the variable oStyle is not 'seen' by the message form's
cmdOkNo_Click procedure. Should be simple but I've gone blank:

From a form I call a custom message box form which can have a combination
of
Yes, No, Cancel or OK cmdbuttons. However I use only 3 buttons by
switching
No and Ok on the same button. The messaging and configuring of the message
box is done in a module:

Public Function oMsgBox1(oStyle As String, oNumPrompts As Long, Prompt1 As
String, Prompt2 As String, Prompt3 As String, Prompt4 As String, Title As
String)

..code

End Function

The oStyle string can be "OK" or "YNC" or "YN"

oStyle, boMsgYes, boMsgNo, and boMsgCancel are declared globally
elsewhere.

In the message form code I have:

Private Sub cmdOkNo_Click()
If oStyle = "YN" Or oStyle = "YNC" Then ''' oStyle remains ""
boMsgNo = True
End If
other stuff
End Sub

Private Sub cmdYes_Click()
boMsgYes = True
other stuff
End Sub

Private Sub cmdCancel_Click()
boMsgCancel = True
other stuff
End Sub

T.I.A.

Geoff



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default Variable not seen

But how would I pass parameters if I used a Sub instead of the current
function?

The message box can be called from a module or the main form for example:

oMsgBox1 _
oStyle:="OK", _
oNumPrompts:=2, _
Prompt1:="xxx is already open ...", _
Prompt2:="... cannot open another version", _
Prompt3:="", _
Prompt4:="", _
Title:="Formxxx"
LoadfrmMsgBox1

Geoff
"Jim Rech" wrote:

oStyle, boMsgYes, boMsgNo, and boMsgCancel are declared globally
elsewhere.


Maybe so but your function declares a local set of variables with the same
names:

Function oMsgBox1(oStyle As String, oNumPrompts As Long, Prompt1 As
String, Prompt2 As String, Prompt3 As String, Prompt4 As String, Title As
String)


You can go two ways at least-

1. Set the global values before calling Function oMsgBox1 and pass nothing
to it.
2. Set global versions of the local variables in the function:

Function oMsgBox1(...)
PuboStyle=oStyle

Btw, if your Function oMsgBox1 returns nothing, as it appears, it shouldn't
be a function. Make it a Sub.

--
Jim
"Geoff" wrote in message
...
|I cannot work out why the variable oStyle is not 'seen' by the message form's
| cmdOkNo_Click procedure. Should be simple but I've gone blank:
|
| From a form I call a custom message box form which can have a combination
of
| Yes, No, Cancel or OK cmdbuttons. However I use only 3 buttons by
switching
| No and Ok on the same button. The messaging and configuring of the message
| box is done in a module:
|
| Public Function oMsgBox1(oStyle As String, oNumPrompts As Long, Prompt1 As
| String, Prompt2 As String, Prompt3 As String, Prompt4 As String, Title As
| String)
|
| ..code
|
| End Function
|
| The oStyle string can be "OK" or "YNC" or "YN"
|
| oStyle, boMsgYes, boMsgNo, and boMsgCancel are declared globally
elsewhere.
|
| In the message form code I have:
|
| Private Sub cmdOkNo_Click()
| If oStyle = "YN" Or oStyle = "YNC" Then ''' oStyle remains ""
| boMsgNo = True
| End If
| other stuff
| End Sub
|
| Private Sub cmdYes_Click()
| boMsgYes = True
| other stuff
| End Sub
|
| Private Sub cmdCancel_Click()
| boMsgCancel = True
| other stuff
| End Sub
|
| T.I.A.
|
| Geoff
|



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default Variable not seen

oMsgBox configures the message box ie width, height and shows the message and
required buttons. As the responses are needed elsewhere in the code I set
Boolean values to each button.

I have put the function in a module - should it be in the form code?

Geoff

"Bob Phillips" wrote:

If oStyle is a global variable, why is it also an argument to oMsgBox?

What does oMsgBox do?

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Geoff" wrote in message
...
I cannot work out why the variable oStyle is not 'seen' by the message form's
cmdOkNo_Click procedure. Should be simple but I've gone blank:

From a form I call a custom message box form which can have a combination
of
Yes, No, Cancel or OK cmdbuttons. However I use only 3 buttons by
switching
No and Ok on the same button. The messaging and configuring of the message
box is done in a module:

Public Function oMsgBox1(oStyle As String, oNumPrompts As Long, Prompt1 As
String, Prompt2 As String, Prompt3 As String, Prompt4 As String, Title As
String)

..code

End Function

The oStyle string can be "OK" or "YNC" or "YN"

oStyle, boMsgYes, boMsgNo, and boMsgCancel are declared globally
elsewhere.

In the message form code I have:

Private Sub cmdOkNo_Click()
If oStyle = "YN" Or oStyle = "YNC" Then ''' oStyle remains ""
boMsgNo = True
End If
other stuff
End Sub

Private Sub cmdYes_Click()
boMsgYes = True
other stuff
End Sub

Private Sub cmdCancel_Click()
boMsgCancel = True
other stuff
End Sub

T.I.A.

Geoff






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 533
Default Variable not seen

But how would I pass parameters if I used a Sub instead of the current
function?


You can pass arguments to subs or functions. Their only difference is that
functions _return_ results.

--
Jim
"Geoff" wrote in message
...
| But how would I pass parameters if I used a Sub instead of the current
| function?
|
| The message box can be called from a module or the main form for example:
|
| oMsgBox1 _
| oStyle:="OK", _
| oNumPrompts:=2, _
| Prompt1:="xxx is already open ...", _
| Prompt2:="... cannot open another version", _
| Prompt3:="", _
| Prompt4:="", _
| Title:="Formxxx"
| LoadfrmMsgBox1
|
| Geoff
| "Jim Rech" wrote:
|
| oStyle, boMsgYes, boMsgNo, and boMsgCancel are declared globally
| elsewhere.
|
| Maybe so but your function declares a local set of variables with the
same
| names:
|
| Function oMsgBox1(oStyle As String, oNumPrompts As Long, Prompt1 As
| String, Prompt2 As String, Prompt3 As String, Prompt4 As String, Title
As
| String)
|
| You can go two ways at least-
|
| 1. Set the global values before calling Function oMsgBox1 and pass
nothing
| to it.
| 2. Set global versions of the local variables in the function:
|
| Function oMsgBox1(...)
| PuboStyle=oStyle
|
| Btw, if your Function oMsgBox1 returns nothing, as it appears, it
shouldn't
| be a function. Make it a Sub.
|
| --
| Jim
| "Geoff" wrote in message
| ...
| |I cannot work out why the variable oStyle is not 'seen' by the message
form's
| | cmdOkNo_Click procedure. Should be simple but I've gone blank:
| |
| | From a form I call a custom message box form which can have a
combination
| of
| | Yes, No, Cancel or OK cmdbuttons. However I use only 3 buttons by
| switching
| | No and Ok on the same button. The messaging and configuring of the
message
| | box is done in a module:
| |
| | Public Function oMsgBox1(oStyle As String, oNumPrompts As Long,
Prompt1 As
| | String, Prompt2 As String, Prompt3 As String, Prompt4 As String, Title
As
| | String)
| |
| | ..code
| |
| | End Function
| |
| | The oStyle string can be "OK" or "YNC" or "YN"
| |
| | oStyle, boMsgYes, boMsgNo, and boMsgCancel are declared globally
| elsewhere.
| |
| | In the message form code I have:
| |
| | Private Sub cmdOkNo_Click()
| | If oStyle = "YN" Or oStyle = "YNC" Then ''' oStyle remains ""
| | boMsgNo = True
| | End If
| | other stuff
| | End Sub
| |
| | Private Sub cmdYes_Click()
| | boMsgYes = True
| | other stuff
| | End Sub
| |
| | Private Sub cmdCancel_Click()
| | boMsgCancel = True
| | other stuff
| | End Sub
| |
| | T.I.A.
| |
| | Geoff
| |
|
|
|


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Variable not seen

As it is public, being in a module should not matter.

Where does the function get called, and with what values?

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Geoff" wrote in message
...
oMsgBox configures the message box ie width, height and shows the message
and
required buttons. As the responses are needed elsewhere in the code I set
Boolean values to each button.

I have put the function in a module - should it be in the form code?

Geoff

"Bob Phillips" wrote:

If oStyle is a global variable, why is it also an argument to oMsgBox?

What does oMsgBox do?

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Geoff" wrote in message
...
I cannot work out why the variable oStyle is not 'seen' by the message
form's
cmdOkNo_Click procedure. Should be simple but I've gone blank:

From a form I call a custom message box form which can have a
combination
of
Yes, No, Cancel or OK cmdbuttons. However I use only 3 buttons by
switching
No and Ok on the same button. The messaging and configuring of the
message
box is done in a module:

Public Function oMsgBox1(oStyle As String, oNumPrompts As Long, Prompt1
As
String, Prompt2 As String, Prompt3 As String, Prompt4 As String, Title
As
String)

..code

End Function

The oStyle string can be "OK" or "YNC" or "YN"

oStyle, boMsgYes, boMsgNo, and boMsgCancel are declared globally
elsewhere.

In the message form code I have:

Private Sub cmdOkNo_Click()
If oStyle = "YN" Or oStyle = "YNC" Then ''' oStyle remains ""
boMsgNo = True
End If
other stuff
End Sub

Private Sub cmdYes_Click()
boMsgYes = True
other stuff
End Sub

Private Sub cmdCancel_Click()
boMsgCancel = True
other stuff
End Sub

T.I.A.

Geoff






  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default Variable not seen

The function can be called 14 locations altogether. For example:

Private Sub oApp_WorkbookBeforeClose(ByVal Wb As Workbook, Cancel As Boolean)

'''check for open Form
If UserForms.Count 0 Then
If UserForms(0).Name = "xxxx" Then
If fileToProcessName = ActiveWorkbook.Name Then
oMsgBox1 _
oStyle:="OK", _
oNumPrompts:=2, _
Prompt1:="You are about to close the workbook with
xxxx still open ...", _
Prompt2:="... please close xxxx first", _
Prompt3:="", _
Prompt4:="", _
Title:="Formxxx"
LoadfrmMsgBox1
Cancel = True
Exit Sub
End If
End If
End If
End Sub

or from a module
If Sheets.Count 1 Then
oMsgBox1 _
oStyle:="YN", _
oNumPrompts:=2, _
Prompt1:="The workbook is about to be reconfigured", _
Prompt2:="Do you wish to continue ?", _
Prompt3:="", _
Prompt4:="", _
Title:="Formxxx"
LoadfrmMsgBox1
If Not boMsgYes Then Exit Sub
End If

or from the main form

Private Sub cmdExecute_Click()
oMsgBox1 _
oStyle:="OK", _
oNumPrompts:=4, _
Prompt1:="Records Processed", _
Prompt2:="Original = " & totalRecords, _
Prompt3:="Usable = " & finalRecords, _
Prompt4:="Removed = " & totalRecords - finalRecords, _
Title:="Formxxx"
LoadfrmMsgBox1
other stuff
End Sub

When I deleted oStyle as a global, oStyle in this became "Empty" instead of ""

Private Sub cmdOkNo_Click()
If oStyle = "YN" Or oStyle = "YNC" Then ''' oStyle remains ""
boMsgNo = True
End If
other stuff
End Sub

Geoff

"Bob Phillips" wrote:

As it is public, being in a module should not matter.

Where does the function get called, and with what values?

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Geoff" wrote in message
...
oMsgBox configures the message box ie width, height and shows the message
and
required buttons. As the responses are needed elsewhere in the code I set
Boolean values to each button.

I have put the function in a module - should it be in the form code?

Geoff

"Bob Phillips" wrote:

If oStyle is a global variable, why is it also an argument to oMsgBox?

What does oMsgBox do?

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Geoff" wrote in message
...
I cannot work out why the variable oStyle is not 'seen' by the message
form's
cmdOkNo_Click procedure. Should be simple but I've gone blank:

From a form I call a custom message box form which can have a
combination
of
Yes, No, Cancel or OK cmdbuttons. However I use only 3 buttons by
switching
No and Ok on the same button. The messaging and configuring of the
message
box is done in a module:

Public Function oMsgBox1(oStyle As String, oNumPrompts As Long, Prompt1
As
String, Prompt2 As String, Prompt3 As String, Prompt4 As String, Title
As
String)

..code

End Function

The oStyle string can be "OK" or "YNC" or "YN"

oStyle, boMsgYes, boMsgNo, and boMsgCancel are declared globally
elsewhere.

In the message form code I have:

Private Sub cmdOkNo_Click()
If oStyle = "YN" Or oStyle = "YNC" Then ''' oStyle remains ""
boMsgNo = True
End If
other stuff
End Sub

Private Sub cmdYes_Click()
boMsgYes = True
other stuff
End Sub

Private Sub cmdCancel_Click()
boMsgCancel = True
other stuff
End Sub

T.I.A.

Geoff







  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default Variable not seen

Hi Jim
I'll go with suggestion 2 and set PuboStyle = oStyle. It works fine in all
the differing scenarios where I call the function.

Many thanks

Geoff



"Jim Rech" wrote:

But how would I pass parameters if I used a Sub instead of the current
function?


You can pass arguments to subs or functions. Their only difference is that
functions _return_ results.

--
Jim
"Geoff" wrote in message
...
| But how would I pass parameters if I used a Sub instead of the current
| function?
|
| The message box can be called from a module or the main form for example:
|
| oMsgBox1 _
| oStyle:="OK", _
| oNumPrompts:=2, _
| Prompt1:="xxx is already open ...", _
| Prompt2:="... cannot open another version", _
| Prompt3:="", _
| Prompt4:="", _
| Title:="Formxxx"
| LoadfrmMsgBox1
|
| Geoff
| "Jim Rech" wrote:
|
| oStyle, boMsgYes, boMsgNo, and boMsgCancel are declared globally
| elsewhere.
|
| Maybe so but your function declares a local set of variables with the
same
| names:
|
| Function oMsgBox1(oStyle As String, oNumPrompts As Long, Prompt1 As
| String, Prompt2 As String, Prompt3 As String, Prompt4 As String, Title
As
| String)
|
| You can go two ways at least-
|
| 1. Set the global values before calling Function oMsgBox1 and pass
nothing
| to it.
| 2. Set global versions of the local variables in the function:
|
| Function oMsgBox1(...)
| PuboStyle=oStyle
|
| Btw, if your Function oMsgBox1 returns nothing, as it appears, it
shouldn't
| be a function. Make it a Sub.
|
| --
| Jim
| "Geoff" wrote in message
| ...
| |I cannot work out why the variable oStyle is not 'seen' by the message
form's
| | cmdOkNo_Click procedure. Should be simple but I've gone blank:
| |
| | From a form I call a custom message box form which can have a
combination
| of
| | Yes, No, Cancel or OK cmdbuttons. However I use only 3 buttons by
| switching
| | No and Ok on the same button. The messaging and configuring of the
message
| | box is done in a module:
| |
| | Public Function oMsgBox1(oStyle As String, oNumPrompts As Long,
Prompt1 As
| | String, Prompt2 As String, Prompt3 As String, Prompt4 As String, Title
As
| | String)
| |
| | ..code
| |
| | End Function
| |
| | The oStyle string can be "OK" or "YNC" or "YN"
| |
| | oStyle, boMsgYes, boMsgNo, and boMsgCancel are declared globally
| elsewhere.
| |
| | In the message form code I have:
| |
| | Private Sub cmdOkNo_Click()
| | If oStyle = "YN" Or oStyle = "YNC" Then ''' oStyle remains ""
| | boMsgNo = True
| | End If
| | other stuff
| | End Sub
| |
| | Private Sub cmdYes_Click()
| | boMsgYes = True
| | other stuff
| | End Sub
| |
| | Private Sub cmdCancel_Click()
| | boMsgCancel = True
| | other stuff
| | End Sub
| |
| | T.I.A.
| |
| | Geoff
| |
|
|
|



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default Variable not seen

Thanks for your responses. I'll go with Jim's suggestion 2 PuboStyle =
oStyle in the function and delete oStyle as a global.

Geoff

"Bob Phillips" wrote:

As it is public, being in a module should not matter.

Where does the function get called, and with what values?

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Geoff" wrote in message
...
oMsgBox configures the message box ie width, height and shows the message
and
required buttons. As the responses are needed elsewhere in the code I set
Boolean values to each button.

I have put the function in a module - should it be in the form code?

Geoff

"Bob Phillips" wrote:

If oStyle is a global variable, why is it also an argument to oMsgBox?

What does oMsgBox do?

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Geoff" wrote in message
...
I cannot work out why the variable oStyle is not 'seen' by the message
form's
cmdOkNo_Click procedure. Should be simple but I've gone blank:

From a form I call a custom message box form which can have a
combination
of
Yes, No, Cancel or OK cmdbuttons. However I use only 3 buttons by
switching
No and Ok on the same button. The messaging and configuring of the
message
box is done in a module:

Public Function oMsgBox1(oStyle As String, oNumPrompts As Long, Prompt1
As
String, Prompt2 As String, Prompt3 As String, Prompt4 As String, Title
As
String)

..code

End Function

The oStyle string can be "OK" or "YNC" or "YN"

oStyle, boMsgYes, boMsgNo, and boMsgCancel are declared globally
elsewhere.

In the message form code I have:

Private Sub cmdOkNo_Click()
If oStyle = "YN" Or oStyle = "YNC" Then ''' oStyle remains ""
boMsgNo = True
End If
other stuff
End Sub

Private Sub cmdYes_Click()
boMsgYes = True
other stuff
End Sub

Private Sub cmdCancel_Click()
boMsgCancel = True
other stuff
End Sub

T.I.A.

Geoff







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
Run-Time error '91': Object variable of With block variable not set jammin1911 Excel Programming 3 June 6th 06 06:36 PM
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM
Run-time error '91': "Object variable or With block variable not set Mike[_92_] Excel Programming 2 December 30th 04 10:59 AM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM


All times are GMT +1. The time now is 07:47 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"