PC Review


Reply
Thread Tools Rate Thread

Convert Excel variable to Access variable

 
 
=?Utf-8?B?QW5keQ==?=
Guest
Posts: n/a
 
      17th Mar 2006
I have opened an Excel spreadsheet from Access code and passed the value of a
particular cell (in text format) to an Access varaible (pubg1) in Variant
format - fine.

When I try to covert the Access variable to an Integer variable (intvar)
using the Val function the code fails with an overflow error.

Can any one make sense of this? Subset of the code :-

Dim pubg1 as Variant
Dim intvar as Integer

Set objWkb = objXL.Workbooks.Open("c:\PM.xls")
Set objSht1 = objWkb.Worksheets("PM")
i = 3

With objXL

.Visible = False

With objSht1

pubg1 = .Range(.Cells(i, 1), .Cells(i, 1)).Value ' range
format is text

End With

.Quit

End With

objXL.Quit
Set objSht1 = Nothing
Set objWkb = Nothing
Set objXL = Nothing

intvar = Val(pubg1) ' fails here with overflow error and err value 6.

Thanks.




 
Reply With Quote
 
 
 
 
Brendan Reynolds
Guest
Posts: n/a
 
      17th Mar 2006
What's the value stored in 'pubg1' at that point? Is it within the valid
range of an integer? (-32,768 to 32,767)

--
Brendan Reynolds
Access MVP

"Andy" <(E-Mail Removed)> wrote in message
news:241B3448-659A-4DAB-BD1F-(E-Mail Removed)...
>I have opened an Excel spreadsheet from Access code and passed the value of
>a
> particular cell (in text format) to an Access varaible (pubg1) in Variant
> format - fine.
>
> When I try to covert the Access variable to an Integer variable (intvar)
> using the Val function the code fails with an overflow error.
>
> Can any one make sense of this? Subset of the code :-
>
> Dim pubg1 as Variant
> Dim intvar as Integer
>
> Set objWkb = objXL.Workbooks.Open("c:\PM.xls")
> Set objSht1 = objWkb.Worksheets("PM")
> i = 3
>
> With objXL
>
> .Visible = False
>
> With objSht1
>
> pubg1 = .Range(.Cells(i, 1), .Cells(i, 1)).Value ' range
> format is text
>
> End With
>
> .Quit
>
> End With
>
> objXL.Quit
> Set objSht1 = Nothing
> Set objWkb = Nothing
> Set objXL = Nothing
>
> intvar = Val(pubg1) ' fails here with overflow error and err value 6.
>
> Thanks.
>
>
>
>



 
Reply With Quote
 
=?Utf-8?B?QW5keQ==?=
Guest
Posts: n/a
 
      17th Mar 2006
Yes - sorry I should have said - the Excel cell contains the value "345578"
which is passed to pubg1

"Brendan Reynolds" wrote:

> What's the value stored in 'pubg1' at that point? Is it within the valid
> range of an integer? (-32,768 to 32,767)
>
> --
> Brendan Reynolds
> Access MVP
>
> "Andy" <(E-Mail Removed)> wrote in message
> news:241B3448-659A-4DAB-BD1F-(E-Mail Removed)...
> >I have opened an Excel spreadsheet from Access code and passed the value of
> >a
> > particular cell (in text format) to an Access varaible (pubg1) in Variant
> > format - fine.
> >
> > When I try to covert the Access variable to an Integer variable (intvar)
> > using the Val function the code fails with an overflow error.
> >
> > Can any one make sense of this? Subset of the code :-
> >
> > Dim pubg1 as Variant
> > Dim intvar as Integer
> >
> > Set objWkb = objXL.Workbooks.Open("c:\PM.xls")
> > Set objSht1 = objWkb.Worksheets("PM")
> > i = 3
> >
> > With objXL
> >
> > .Visible = False
> >
> > With objSht1
> >
> > pubg1 = .Range(.Cells(i, 1), .Cells(i, 1)).Value ' range
> > format is text
> >
> > End With
> >
> > .Quit
> >
> > End With
> >
> > objXL.Quit
> > Set objSht1 = Nothing
> > Set objWkb = Nothing
> > Set objXL = Nothing
> >
> > intvar = Val(pubg1) ' fails here with overflow error and err value 6.
> >
> > Thanks.
> >
> >
> >
> >

>
>
>

 
Reply With Quote
 
Brendan Reynolds
Guest
Posts: n/a
 
      17th Mar 2006
Well there you go then. You can't put 345,578 in an integer, the maximum
value of an integer is 32,767. You'll need to use a long instead.

--
Brendan Reynolds
Access MVP


"Andy" <(E-Mail Removed)> wrote in message
news:E9A7567B-A091-44F5-A4AE-(E-Mail Removed)...
> Yes - sorry I should have said - the Excel cell contains the value
> "345578"
> which is passed to pubg1
>
> "Brendan Reynolds" wrote:
>
>> What's the value stored in 'pubg1' at that point? Is it within the valid
>> range of an integer? (-32,768 to 32,767)
>>
>> --
>> Brendan Reynolds
>> Access MVP
>>
>> "Andy" <(E-Mail Removed)> wrote in message
>> news:241B3448-659A-4DAB-BD1F-(E-Mail Removed)...
>> >I have opened an Excel spreadsheet from Access code and passed the value
>> >of
>> >a
>> > particular cell (in text format) to an Access varaible (pubg1) in
>> > Variant
>> > format - fine.
>> >
>> > When I try to covert the Access variable to an Integer variable
>> > (intvar)
>> > using the Val function the code fails with an overflow error.
>> >
>> > Can any one make sense of this? Subset of the code :-
>> >
>> > Dim pubg1 as Variant
>> > Dim intvar as Integer
>> >
>> > Set objWkb = objXL.Workbooks.Open("c:\PM.xls")
>> > Set objSht1 = objWkb.Worksheets("PM")
>> > i = 3
>> >
>> > With objXL
>> >
>> > .Visible = False
>> >
>> > With objSht1
>> >
>> > pubg1 = .Range(.Cells(i, 1), .Cells(i, 1)).Value ' range
>> > format is text
>> >
>> > End With
>> >
>> > .Quit
>> >
>> > End With
>> >
>> > objXL.Quit
>> > Set objSht1 = Nothing
>> > Set objWkb = Nothing
>> > Set objXL = Nothing
>> >
>> > intvar = Val(pubg1) ' fails here with overflow error and err value 6.
>> >
>> > Thanks.
>> >
>> >
>> >
>> >

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?QW5keQ==?=
Guest
Posts: n/a
 
      17th Mar 2006
Excellent - Thanks.

"Brendan Reynolds" wrote:

> Well there you go then. You can't put 345,578 in an integer, the maximum
> value of an integer is 32,767. You'll need to use a long instead.
>
> --
> Brendan Reynolds
> Access MVP
>
>
> "Andy" <(E-Mail Removed)> wrote in message
> news:E9A7567B-A091-44F5-A4AE-(E-Mail Removed)...
> > Yes - sorry I should have said - the Excel cell contains the value
> > "345578"
> > which is passed to pubg1
> >
> > "Brendan Reynolds" wrote:
> >
> >> What's the value stored in 'pubg1' at that point? Is it within the valid
> >> range of an integer? (-32,768 to 32,767)
> >>
> >> --
> >> Brendan Reynolds
> >> Access MVP
> >>
> >> "Andy" <(E-Mail Removed)> wrote in message
> >> news:241B3448-659A-4DAB-BD1F-(E-Mail Removed)...
> >> >I have opened an Excel spreadsheet from Access code and passed the value
> >> >of
> >> >a
> >> > particular cell (in text format) to an Access varaible (pubg1) in
> >> > Variant
> >> > format - fine.
> >> >
> >> > When I try to covert the Access variable to an Integer variable
> >> > (intvar)
> >> > using the Val function the code fails with an overflow error.
> >> >
> >> > Can any one make sense of this? Subset of the code :-
> >> >
> >> > Dim pubg1 as Variant
> >> > Dim intvar as Integer
> >> >
> >> > Set objWkb = objXL.Workbooks.Open("c:\PM.xls")
> >> > Set objSht1 = objWkb.Worksheets("PM")
> >> > i = 3
> >> >
> >> > With objXL
> >> >
> >> > .Visible = False
> >> >
> >> > With objSht1
> >> >
> >> > pubg1 = .Range(.Cells(i, 1), .Cells(i, 1)).Value ' range
> >> > format is text
> >> >
> >> > End With
> >> >
> >> > .Quit
> >> >
> >> > End With
> >> >
> >> > objXL.Quit
> >> > Set objSht1 = Nothing
> >> > Set objWkb = Nothing
> >> > Set objXL = Nothing
> >> >
> >> > intvar = Val(pubg1) ' fails here with overflow error and err value 6.
> >> >
> >> > Thanks.
> >> >
> >> >
> >> >
> >> >
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to graph x-variable versus y-variable in Excel ? Mojjara Microsoft Excel New Users 3 2nd Apr 2009 06:38 PM
VBA Access - Moving parts of a program to DLLs? Error 91.. "Object variable or With block variable not set" axs221 Microsoft Access 10 25th Jul 2006 01:53 PM
convert a numeric variable to a character variable =?Utf-8?B?QmxpbmRh?= Microsoft Access 3 28th Jun 2006 10:34 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 Microsoft Excel Discussion 1 9th Jul 2005 02:04 AM
How do I convert an integer variable to a string variable? =?Utf-8?B?ZHVtYmFzcw==?= Microsoft Excel Programming 2 21st May 2004 08:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:17 PM.