DIM Statement

  • Thread starter Thread starter David Portwood
  • Start date Start date
D

David Portwood

I read a warning that a Dim statement such as:

Dim mySQL, RecSource, fldNames As String

is incorrect and should instead be written:

Dim mySQL as String, RecSource as String, fldNames as String

Is this true? It compiles ok. What is the problem?
 
Yes. That's correct.

This is a valid line of code:
Dim mySQL
Since you did not specify a type, you get a variant.

Similarly the line:
Dim mySQL, RecSource, fldNames As String
gives you 2 untyped variables (so Variant), and one string.

That's a trap if you expect to get 3 strings.

To demonstate it's true, add these 2 lines after your single-line
declaration:
mySQL = Null
fldNames = Null
Since the Variant can contain Null, the first line succeeds.
Since the String cannot contain Null, the 2nd line gives error 94 when
executed.
 

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