Data Type Declaration Statements

All,

I am still getting my feet wet with devlopment so bare with me please!!

An easy question for you all I hope?

Can I declare mutiple variables and associated data types on one line of code in Access VBA?

I have enclosed a sample for you to see what I am doing.

CF
Dim vMAID As Long, vPodStateCode as Integer, vRefNo As Long, vDestLocNo As Long

Open in new window

creativefusionAsked:
Who is Participating?
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
To avoid problems down the road and minimize issues ... this is your best move:


Dim vRefNo As Long, vMAID as Long, vStateCode as Integer, vTest as String

Right off, I forget what can happen, but I'm pretty sure that w/o As Long for vRefNo ... it will be a Variant.

I prefer this scenario:


Dim vRefNo As Long, vMAID as Long
Dim vStateCode as Integer
Dim vTest as String

ie ... separate lines for each data type.

mx
0
 
Rey Obrero (Capricorn1)Commented:
Yes, that is a correct way of doing the declaration
0
 
Rey Obrero (Capricorn1)Commented:
you can also do this

Dim vMAID As Long, vPodStateCode As Integer, _
    vRefNo As Long, vDestLocNo As Long
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:


Dim vMAID As Long, vPodStateCode as Integer, vRefNo As Long, vDestLocNo As Long

Just noting ... when you do all the declarations on a single, be *sure* you data type each variable ... as you have done.

mx
0
 
creativefusionAuthor Commented:
Thanks guys.

So I couldn't do this right?

Dim vRefNo, vMAID as Long, vStateCode as Integer, vTest as String

Note: Both vRefNo and vMAID are Long data types...

CF
0
 
creativefusionAuthor Commented:
Perfect as expected.

Thanks guys.
Shaun
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
you are welcome ..

mx
0
 
Rey Obrero (Capricorn1)Commented:
creativefusion,

your question states
<Can I declare mutiple variables and associated data types on one line of code in Access VBA? >

and that is already answered in http:#a35135077 
0
 
creativefusionAuthor Commented:
Hi Caps,

Mate, I aksed the original question and yes you answered it correctly first off. However, as a VB newbee ( and you know I am because you have answered many of my previous posts), we both know how dynamic programming can be to a blind man, so the question changed as I found an issue with another possible scenario beyond my initial post.

DatabseMX answered the additional questions I posted hense the reason why I awarded the most points to him.

Is it really supposed to be so confronting for a learner on EE?

Kind regards,
Shaun
0
 
Rey Obrero (Capricorn1)Commented:
<Is it really supposed to be so confronting for a learner on EE?>

no, but there are rules to be followed, (first correct answer gets the accepted answer)

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.