Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Const Fails to work

Const AFile as string = "C:\xxxxx\xxxxx\xxxx.mdb" placed at the top of a
standard module but fails to show in the procedures other than the top
procedure.

Any ideas why??

TIA johnb
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Const Fails to work

On May 19, 9:48 am, johnb wrote:
Const AFile as string = "C:\xxxxx\xxxxx\xxxx.mdb" placed at the top of a
standard module but fails to show in the procedures other than the top
procedure.

Any ideas why??

TIA johnb


Both of the following subs work fine for me. Can you be more specific
about what's happening for you?


Option Explicit

Const AFile As String = "C:\xxxxx\xxxxx\xxxx.mdb"

Public Sub Test()
MsgBox "1: " & AFile
End Sub

Public Sub Test2()
MsgBox "2: " & AFile
End Sub


-Bryan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Const Fails to work

Hi Bryan,
I'm building, using vba, 10 pivottables within a workbook but on seperate
sheets. The procedures are all in one standard module. The code that fails is
the const DBFile. The DBFile just returns "" Except in the top Procedure!

Set PTcache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlExter nal)
'connect to database
con = "ODBC;DSN=MS Access Database;DBQ=" & DBFile

Regard johnb


"Bryan Loeper" wrote:

On May 19, 9:48 am, johnb wrote:
Const AFile as string = "C:\xxxxx\xxxxx\xxxx.mdb" placed at the top of a
standard module but fails to show in the procedures other than the top
procedure.

Any ideas why??

TIA johnb


Both of the following subs work fine for me. Can you be more specific
about what's happening for you?


Option Explicit

Const AFile As String = "C:\xxxxx\xxxxx\xxxx.mdb"

Public Sub Test()
MsgBox "1: " & AFile
End Sub

Public Sub Test2()
MsgBox "2: " & AFile
End Sub


-Bryan


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Const Fails to work

John,
Assuming that statement is in the Declares section of the module, the only
other reason would be a misspelt variable name.
Are you using Option Explicit ?

NickHK

"johnb" wrote in message
...
Hi Bryan,
I'm building, using vba, 10 pivottables within a workbook but on seperate
sheets. The procedures are all in one standard module. The code that fails

is
the const DBFile. The DBFile just returns "" Except in the top Procedure!

Set PTcache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlExter nal)
'connect to database
con = "ODBC;DSN=MS Access Database;DBQ=" & DBFile

Regard johnb


"Bryan Loeper" wrote:

On May 19, 9:48 am, johnb wrote:
Const AFile as string = "C:\xxxxx\xxxxx\xxxx.mdb" placed at the top of

a
standard module but fails to show in the procedures other than the top
procedure.

Any ideas why??

TIA johnb


Both of the following subs work fine for me. Can you be more specific
about what's happening for you?


Option Explicit

Const AFile As String = "C:\xxxxx\xxxxx\xxxx.mdb"

Public Sub Test()
MsgBox "1: " & AFile
End Sub

Public Sub Test2()
MsgBox "2: " & AFile
End Sub


-Bryan




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Const Fails to work

Hi Nick

It smacks you on the nosedoes it not? Option Explicit is the answer. Const
now works perfectly.

Many thanks

johnb



"NickHK" wrote:

John,
Assuming that statement is in the Declares section of the module, the only
other reason would be a misspelt variable name.
Are you using Option Explicit ?

NickHK

"johnb" wrote in message
...
Hi Bryan,
I'm building, using vba, 10 pivottables within a workbook but on seperate
sheets. The procedures are all in one standard module. The code that fails

is
the const DBFile. The DBFile just returns "" Except in the top Procedure!

Set PTcache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlExter nal)
'connect to database
con = "ODBC;DSN=MS Access Database;DBQ=" & DBFile

Regard johnb


"Bryan Loeper" wrote:

On May 19, 9:48 am, johnb wrote:
Const AFile as string = "C:\xxxxx\xxxxx\xxxx.mdb" placed at the top of

a
standard module but fails to show in the procedures other than the top
procedure.

Any ideas why??

TIA johnb

Both of the following subs work fine for me. Can you be more specific
about what's happening for you?


Option Explicit

Const AFile As String = "C:\xxxxx\xxxxx\xxxx.mdb"

Public Sub Test()
MsgBox "1: " & AFile
End Sub

Public Sub Test2()
MsgBox "2: " & AFile
End Sub


-Bryan







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Const Fails to work

John,
For me, there is no reason not to use Option Explicit.
You will avoid wasting time (and hair) on these spelling mistakes.

NickHK

"johnb" wrote in message
...
Hi Nick

It smacks you on the nosedoes it not? Option Explicit is the answer. Const
now works perfectly.

Many thanks

johnb



"NickHK" wrote:

John,
Assuming that statement is in the Declares section of the module, the

only
other reason would be a misspelt variable name.
Are you using Option Explicit ?

NickHK

"johnb" wrote in message
...
Hi Bryan,
I'm building, using vba, 10 pivottables within a workbook but on

seperate
sheets. The procedures are all in one standard module. The code that

fails
is
the const DBFile. The DBFile just returns "" Except in the top

Procedure!

Set PTcache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlExter nal)
'connect to database
con = "ODBC;DSN=MS Access Database;DBQ=" & DBFile

Regard johnb


"Bryan Loeper" wrote:

On May 19, 9:48 am, johnb wrote:
Const AFile as string = "C:\xxxxx\xxxxx\xxxx.mdb" placed at the

top of
a
standard module but fails to show in the procedures other than the

top
procedure.

Any ideas why??

TIA johnb

Both of the following subs work fine for me. Can you be more

specific
about what's happening for you?


Option Explicit

Const AFile As String = "C:\xxxxx\xxxxx\xxxx.mdb"

Public Sub Test()
MsgBox "1: " & AFile
End Sub

Public Sub Test2()
MsgBox "2: " & AFile
End Sub


-Bryan







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
Conditional Formatting: Logical AND fails to work with INDIRECT(.. Hamish Excel Worksheet Functions 5 May 15th 08 04:54 PM
Cell Referal between tabs fails to work properly on home computer [email protected] Excel Worksheet Functions 0 November 28th 06 01:03 AM
Change event fails to work Mark F Excel Worksheet Functions 3 November 10th 05 12:08 PM
Not recognizing a Const Dan T[_3_] Excel Programming 7 July 18th 04 12:45 AM
crash changing const to public const BrianB Excel Programming 0 August 4th 03 10:13 AM


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