error message

  • Thread starter Thread starter ranswrt
  • Start date Start date
R

ranswrt

I have the following code:

db = Range("currentdb")

I have used this code before in other procedures and it has worked. When I
use in a userform_Terminate I get the error

method 'Range' of Object'_Global' failed.

'currentdb' is a named cell on a worksheet.

Why won't this work?
Thanks
 
hi
try
set db = Range("currentdb")

you set objects and a range is an object. values are just equals(=)

regards
FSt1
 
I have

dim db as string

I am trying to get the string from the cell named 'currentdb'. I have used
this same code in other procedures and it has worked fine.
 
Check your spelling of that range name.

And check to make sure that the sheet being looked at actually has a range named
currentdb.
 
hi
a range is an object.
a string is a value.
i am confused now!?!?!?!
if a string then......
dim db as string
db = currentdb.value
else
dim db as range
set db = range("currentdb")

a string is somthing like "i am a string"
a range is someting like A1:R20

are we on the same page?!?!?!?

regards
FSt1
 
hi dave,
thanks for your input.
but did i miss someting about objects and values
please correct me if i'm wrong.

regards
FSt1
 
The OP added this detail:
dim db as string
in the followup post.

So that means that:
db = Range("currentdb")
is relying on the default property of the range (.value).
 
hi
i was unaware of a default value property. i thought that this had to be
specified.
after testing, you're rignt
thanks for correcting me. i learned something.
disregards all of my posts.

regards
FSt1
 
I think it's a good idea to specify the property that you want. I like it
because it makes the code much more self-documenting.
hi
i was unaware of a default value property. i thought that this had to be
specified.
after testing, you're rignt
thanks for correcting me. i learned something.
disregards all of my posts.

regards
FSt1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top