Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Wierd variable values problem

I have an excel purchase order form automated using macros. I have a
module named "Setup" in which I define all of my public variables (29
to be exact). In it is an "Auto_Open" sub in which I assign initial
values to the variables. When the users finish filling in the form and
try to print or save it I run a "Check_Entries" sub which checks to
insure specific cells contain data. With some regularity a user will
receive the "Object variable or With block variable not set" error. It
occurs on the first line of code of the "Check_Entries" sub that
contains a variable reference. Further investigation indicates that
defined variables have been lost. This happens about once in every 50
executions of the .xls. It occurs on different machines, different
users and both XP SP2 and Win98SE OS's. I have not been able to
intentionally duplicate the error. Can anyone give me any ideas as to
what might be going on?

BrianG

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Wierd variable values problem

Do you have any "End" lines in your code--not "end if", "End with" "end
sub"--just plain old End's?

if a=b then
end
else
'do something
end if

End's will reset those variables.

I think I'd get rid of them somehow.

And you may want to create a dedicated subroutine that initializes those
variables.

Then you could use:

Public VariablesAreInitialized as boolean
sub initializeVariables()
'do all the initialization
variablesareinitialized = true
end sub

Then in each of your subroutines:

if variablesareinitialized = false then
call initializeVariables
end if

(assumes that you don't do anything to those variables once they're
initialized.)



wrote:

I have an excel purchase order form automated using macros. I have a
module named "Setup" in which I define all of my public variables (29
to be exact). In it is an "Auto_Open" sub in which I assign initial
values to the variables. When the users finish filling in the form and
try to print or save it I run a "Check_Entries" sub which checks to
insure specific cells contain data. With some regularity a user will
receive the "Object variable or With block variable not set" error. It
occurs on the first line of code of the "Check_Entries" sub that
contains a variable reference. Further investigation indicates that
defined variables have been lost. This happens about once in every 50
executions of the .xls. It occurs on different machines, different
users and both XP SP2 and Win98SE OS's. I have not been able to
intentionally duplicate the error. Can anyone give me any ideas as to
what might be going on?

BrianG


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Wierd variable values problem

Thanks for the hint to look for an errant "End" statement but no luck
finding one. Still no explanation as to what is causing the error.
When the error occurs I have gone into Debug mode and added Public and
Set statements to try to figure out what is going on. The error occurs
on every line of code where I check a cell for a value. Maybe the way
I'm doing that is problematic. Should this work:

Public objDate as Range
Public objShipTo as Range

Set objDate = Range("H15")
Set objShipTo = Range("H16")

Call CheckEntries

CheckEntries()
If objDate.Value = " " Then
display error message
Exit Sub
If objShipTo.Value = " " Then
display error message
Exit Sub
End Sub

--
BrianG

Dave Peterson wrote:
Do you have any "End" lines in your code--not "end if", "End with" "end
sub"--just plain old End's?

if a=b then
end
else
'do something
end if

End's will reset those variables.

I think I'd get rid of them somehow.

And you may want to create a dedicated subroutine that initializes those
variables.

Then you could use:

Public VariablesAreInitialized as boolean
sub initializeVariables()
'do all the initialization
variablesareinitialized = true
end sub

Then in each of your subroutines:

if variablesareinitialized = false then
call initializeVariables
end if

(assumes that you don't do anything to those variables once they're
initialized.)



wrote:

I have an excel purchase order form automated using macros. I have a
module named "Setup" in which I define all of my public variables (29
to be exact). In it is an "Auto_Open" sub in which I assign initial
values to the variables. When the users finish filling in the form and
try to print or save it I run a "Check_Entries" sub which checks to
insure specific cells contain data. With some regularity a user will
receive the "Object variable or With block variable not set" error. It
occurs on the first line of code of the "Check_Entries" sub that
contains a variable reference. Further investigation indicates that
defined variables have been lost. This happens about once in every 50
executions of the .xls. It occurs on different machines, different
users and both XP SP2 and Win98SE OS's. I have not been able to
intentionally duplicate the error. Can anyone give me any ideas as to
what might be going on?

BrianG


--

Dave Peterson


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Wierd variable values problem

Is that code in the userform's module or somewhere else?

Do you hide that form or unload it?

Are those public declarations in a general module?

I think you'll have to provide a bit more info.




wrote:

Thanks for the hint to look for an errant "End" statement but no luck
finding one. Still no explanation as to what is causing the error.
When the error occurs I have gone into Debug mode and added Public and
Set statements to try to figure out what is going on. The error occurs
on every line of code where I check a cell for a value. Maybe the way
I'm doing that is problematic. Should this work:

Public objDate as Range
Public objShipTo as Range

Set objDate = Range("H15")
Set objShipTo = Range("H16")

Call CheckEntries

CheckEntries()
If objDate.Value = " " Then
display error message
Exit Sub
If objShipTo.Value = " " Then
display error message
Exit Sub
End Sub

--
BrianG

Dave Peterson wrote:
Do you have any "End" lines in your code--not "end if", "End with" "end
sub"--just plain old End's?

if a=b then
end
else
'do something
end if

End's will reset those variables.

I think I'd get rid of them somehow.

And you may want to create a dedicated subroutine that initializes those
variables.

Then you could use:

Public VariablesAreInitialized as boolean
sub initializeVariables()
'do all the initialization
variablesareinitialized = true
end sub

Then in each of your subroutines:

if variablesareinitialized = false then
call initializeVariables
end if

(assumes that you don't do anything to those variables once they're
initialized.)



wrote:

I have an excel purchase order form automated using macros. I have a
module named "Setup" in which I define all of my public variables (29
to be exact). In it is an "Auto_Open" sub in which I assign initial
values to the variables. When the users finish filling in the form and
try to print or save it I run a "Check_Entries" sub which checks to
insure specific cells contain data. With some regularity a user will
receive the "Object variable or With block variable not set" error. It
occurs on the first line of code of the "Check_Entries" sub that
contains a variable reference. Further investigation indicates that
defined variables have been lost. This happens about once in every 50
executions of the .xls. It occurs on different machines, different
users and both XP SP2 and Win98SE OS's. I have not been able to
intentionally duplicate the error. Can anyone give me any ideas as to
what might be going on?

BrianG


--

Dave Peterson


--

Dave Peterson
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
Wierd VBA happenings... LT Excel Discussion (Misc queries) 4 March 15th 07 02:10 PM
Very Wierd Execl "Memory" problem Pat Excel Discussion (Misc queries) 3 October 26th 06 03:39 PM
Wierd Save problem Gareth Saunders Excel Discussion (Misc queries) 2 May 11th 06 04:32 PM
WIERD Excel Problem BK Setting up and Configuration of Excel 8 April 7th 06 12:17 AM
Problem trying to us a range variable as an array variable TBA[_2_] Excel Programming 4 September 27th 03 02:56 PM


All times are GMT +1. The time now is 12:31 AM.

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"