DIM Statement

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? 


0
David
4/21/2007 4:23:48 PM
access 16762 articles. 3 followers. Follow

2 Replies
975 Views

Similar Articles

[PageSpeed] 50

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.

-- 
Allen Browne - Microsoft MVP.  Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"David Portwood" <Mondrogan@yahoo.com> wrote in message
news:462a3a7e$0$18898$4c368faf@roadrunner.com...
>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? 

0
Allen
4/21/2007 4:54:16 PM
I see. I will keep this in mind.

Thanks very much, Allen.

"Allen Browne" <AllenBrowne@SeeSig.Invalid> wrote in message 
news:ulPU0WDhHHA.588@TK2MSFTNGP06.phx.gbl...
> 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.
>
> -- 
> Allen Browne - Microsoft MVP.  Perth, Western Australia
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "David Portwood" <Mondrogan@yahoo.com> wrote in message
> news:462a3a7e$0$18898$4c368faf@roadrunner.com...
>>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?
> 


0
David
4/21/2007 7:25:59 PM
Reply:

Similar Artilces:

Macro for Date If Statement
I have a column of Dates, need the Macro to look at all the date in the column and compare to the current date and if the date in the column is more that 365 days old want to turn the date in the column GREEN! Can this be done? Currently there are over 500 dates in the column. Thanks for your help Ray Column? Are the dates in a table? If so then the following will work (with column1) of the table containing the cursor Dim oCell As Cell Dim oRng As Range With Selection.Tables(1) For Each oCell In .Columns(1).Cells Set oRng = oCell.Range oRng.End = oRng...

AND IF STATEMENT
Hi I would like to do the following but have no idea what the format of the formula should be so any help appreciated: =IF(AND(EP86426="Standard",AA86426>0),1,0) So I want cell EP86426 to contain the word standard and I want the cell AA86426 (which in itself has a formula which returns 1 or 0) to be greater than 0. this part of the formula works but I also want to look at cell CK86426 and if its value is greater than zero I want it to return a 1 in cell AB86426 I hope that is clearly explained lol Thanks in advance Sam "Sam Hamman" <sam@theham.com> wrote: ...

Toolbox is dimmed
I need to add and format few controls to a chart (assign a color and/or a macro to each of them). When I select View Toolbox, it pops up, but all controls are dimmed. I can switch to Design Mode in and out, but in both cases controls are dimmed and I can not select it... (I need checkbox, textbox and label) Related question: How do I group them together in a rectangular agea when I finally learn how to put them on the chart? I use two types of charts - radar and bar chart - hope that is irrelevant... thanks you Hi, The toolbox is dimmed because ActiveX controls, those from the Contr...

Is it possible to have If statements in a query?
Hello, I have a subform and in this suform I have a combobox field called "Category". In this combobox I have a select query that pulls the Category and TeamName. On the master form I have a floating combobox called Team. When I choose a team in this field I would like the subform combobox to be narrowed down a little as such if possible... If the Team field on the master form is Accounting I would like the Category combobox to be limitted to "Accounting" and "Other" team names. If the Team field on the master form is ESTABLISHMENT I need the Cate...

Money 2008 does not associate downloaded statement with an account
I download my credit union statement and Money 2008 says the import is complete but it does not ask which account is to accept the data and the import goes no where. I have deleted the temp files, done a quick fix on the Money file, set imports to use standard names, even downloaded the statement to my hard drive and used -file-import- to try to get it. Same thing always happens, file says "import complete" but the data is nowhrer. I have called the credit union and they say there is no problem. I have tried this process on three different XP machines with the same problem ...

Money 2002
I started to have problems downloading my bank statement. It downloads successfully, but the new transactions do not appear in the checking a/c register. Error msg included that qif file did not have date and amount (bank download includes billpayer messages). As I have been attempting to fix this problem, Money stalls on backing up, and I am unable to back up the current file. Any suggestions ...

Using "IF" statements...my problem
One column has one letter in each cell, something between A through E, basically randomly occuring down the entire column. Next to each cell in that column is a number value associated with the letter, but of course each nominal letter (not each instance) may be associated with x different numbers/values, depending on how many times is shows up in the column. ANyway, how do I use "IF, then" statements to sum, say, all the numbers associated with "A"? Hi! Try this: Letters in column A, numeric values in column B. =SUMIF(A:A,"A",B:B) OR: C1 = A =SUMIF(A:A,...

using For statement for populting textbox references
I use the following type of code to populate textboxes in userforms Me.txt1.Value = ws.Range("A10").Value Me.txt2.Value = ws.Range("A11").Value Me.txt3.Value = ws.Range("A12").Value Me.txt4.Value = ws.Range("A13").Value Me.txt5.Value = ws.Range("A14").Value Me.txt6.Value = ws.Range("A15").Value Me.txt7.Value = ws.Range("A16").Value Me.txt8.Value = ws.Range("A17").Value etc etc... Is there a way to use a "For i = 1 to 8" statement which will do the above code : for example Dim i as Integ...

IF STATEMENT HELP NEEDED!!!
I'm trying to create a spread sheet and don't know this program AT ALL! I'm a designer and math and art just don't mix... So, here are the equations... In cell X6 I enter: If C6>D6 then (C6-D6)*5 or If C6<D6 then (D6-C6)*10 But, if cell D6 is yellow --- Put 20 in cell X6 So, I need some sort of identifier in the equation saying whether the cell is yellow or not. I'm sure excel doesn't recognize "yellow" but there must be another way. I can put a letter with a number in that cell if necessary. I'm not sure this is making sence, but if anyon...

Add qualifier to andif statement
I have a spreadsheet formua that I'd like to add a test to, for name in another column. The formula is =SUMIF($F$3:$F$218,">="&A3,$G$3:$G$218) -SUMIF($F$3:$F$218,">"&B2,$G$3:$G$218) In this case I want to test a name in column H and only count G if name is equal So far I know a bunch of ways....that won't work..LOL....can someone help me out thanks. Steve "litngldy" wrote: > I have a spreadsheet formua that I'd like to add a test to, for name in > another column. > The formula is =SUMIF($F$3:$F$218,">="...

Help with SQL Statement for pivot table
I'm trying to put a sql statment from an access query into a pivot table query builder. I built the query in access then took the sql view and tried to put it into the excel query builder -- not working. Access put dbo_ in front of all of the table names so I took that out but it's got other problems too. Not sure how the date range should be specified and I wanted it to search a text field for the word "implant". In access I did this by specifying *implant* but sql doesn't seem to like it. Here's the statement: SELECT ApptPending.CreateDate, ApptPending....

For all of you IF Statement experts.......
I have a dropdown menu in cell A1 with 3 names in it. Jones, Davis, an Smith. In Cell A2 I want the cell to automatically show the codename have given for the respective person in cell A1. Is this possible? I use thie code for just one person, but I dont know how to properl add to it to make it usable for 3 people. =IF(A1="Jones","BIGFISH","") Example.... In cell A1, I select Jones. I want his codename, Bigfish, t automatically appear in cell A2. Thanks in advance. Miles Ree -- mcr ----------------------------------------------------------------------- ...

IF/MAX statement
I need help creating a d\statement that allows me to ise IF and MAX or IF and MIN at the same time in one statement. PLEASE help. ...

IIF Statement
I have a table full of items, below is one example from the table. I am trying to do a query that will display the longest dimension (as L1) for each item. Item field is text, all others are numbers. Here is my data: Item = Y10227 ItemLength = 8.375 ItemWidth = 9.25 ItemHeight = 5.125 Here is the field in my query to determine the largest of the dimensions: L1: IIf([ItemLength]>[ItemHeight] And [ItemWidth],[ItemLength],IIf([ItemHeight]>[ItemLength] And [ItemWidth],[ItemHeight],IIf([Itemwidth]>[itemheight] And [itemlength],[itemwidth]))) The result I am gettin...

RMS and House Acct- printing statements
I have a potential customer who will use house accts and print statements. However, there are some statements that done need to be printed (for example- COD). So - they want a way to be able to filter on what types of statements are printed. They may have 500 customers, but only 300 need to be printed. Today, they Add a code- N3 to the customer record, and then they filter on which customer statements to print that have the code N3 and have a balance greater than 0- and print these statements. Can RMS "filter" on which statements to print that are represented by a code? Andrea...

legal disclosure statement.
Is there any way I can automatically add a legal disclousre at the end of every email sent from my Exchange 5.5 server? http://www.policypatrol.com/Features.htm >-----Original Message----- >Is there any way I can automatically add a legal >disclousre at the end of every email sent from my >Exchange 5.5 server? >. > Here is a link that tells you how to set it up. There is a KB on it too. http://www.msexchange.org/tutorials/Adding_Email_Disclaimer_Text_With_The_IMS_Extension_In_MS_Exchange_55.html "Shirley Cione" <shirleycione@hotmail.com> wrote in...

Pricing Program and If-Then Statements
Hello Everyone, I am new at this macro thing so bear with me. I am designing a pricin program for work. We need to be able to price rectangular roof curb and right now we use a hard copy matrix with numbers based on size. There are all sorts of additional options you can add to the curbs mostly in the form of percentage adds based on size. My questions involve making the program work for a list of curb sizes. Right now I have a macro set up that will give you a final price base on the size and different options, but it will only do it for one curb I need to make a sheet that will allow m...

Australian Banks that are supported for instant statement download
Does anyone know what Australian Banks are supported for the online banking function of Microsoft Money? I know I can export statements from my current bank, however I want a bank that will allow M. Money to connect directly to it so I don't have to do the manual exports. All help appreciated. As far as I think anyone knows who has posted here, there are none, except for those you export from your bank's website. Unless someone knows different.... -- Glyn Simpson, Microsoft MVP - Money http://money.mvps.org Check http://money.mvps.org/faq for tips and fixes for MS Money. To ...

If Statement 01-07-08
I am trying to run a query, but don't know how to go about it. If "Disposition" equals "Rejected", sum the "Lot Quantity" of the "Rejected" records. If "Disposition" does NOT equal "Rejected", sum the "Lot Quantity" of the "Rejected" AND "Accepted" records. Would somebody please help me out? Thanks. It all starts with the data... ?!what data?! Regards Jeff Boyce Microsoft Office/Access MVP "lucky1" <u40483@uwe> wrote in message news:7ddf368da5949@uwe... >I am trying to run...

Downloading Statement enters Duplicate Transactions--Need Advise...
Why would MS Money NOT match downloaded transactions with already entered transactions???? I have been creating my own QIF download from BOA every few days to download into MO7. I create my QIF in Excel by copying and pasting from the BOA website and I import it into MO7 as a regular statement. This works great ....that is until I download the end of the month statement from BOA. When I download THEIR statement, MS Money does not MATCH the transactions. Therefore I end up having two of every transaction (except the ones that were entered from Bills Paid). Since this month I had 155 transact...

Multiple IF statements in a single cell
I am doing a set of projections for a corporate client and want to create a formula to calculate the federal income tax. Is there a way that I can create a formula in a single cell to calculate the tax due by using an IF statement to look at the net income before taxes? I currently have a formula that is an IF/OR statement that will allow me to calculate the tax due if the income falls within two tax brackets. I can not figure out how to create the formula to determine if there is a loss or the income falls within a different tax bracket. Thank you for your repsonses and your hel...

Credit memo not appearing in Sales Statement
Hi, Im using the RM Statement on blank paper but when printing the document out, the credit memo amount won't show. It'll only show the the document no. In the report writter, i pull out 2 column for debit amount and credit amount. Please help. Thanks in advance!! ...

Income Statement
Hi, I made an income statement using AFA when I print it all the amounts are zeros any idea why it is showing like this? thx in advance Hi Saad, Please check the open fiscal year in your Income Statement in AFA and when generating the IS, make sure you change your user date in line with the fiscal period you want the IS to cover. Hope this helps! Cheers, Dennis Araullo, MACS Microsoft Certified Technology Specialist GP,CRM, AX MCITP Installation and Configuration AX 2009 MCITP Database Administrator SQL 2008 Citrix Certified Enterprise Administrator "Saad&...

Show This Folder as an E-mail Address Book Is Dimmed
This is a multi-part message in MIME format. ------=_NextPart_000_000D_01C66ADA.58223750 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I am an administrator of a network with 8 Windows 2003 servers SP1 and 1 = Exchange 2003 SP2. Clients are running Windows XP/Office XP and Windows = 2000/Office 2000.=20 I want to share contacts with the rest of the company, contacts that I = copied from another users Outlook 2000 to the Public Folders item. I = want the contacts to be available in the Global Addresslist but in the = Properties|Outlook ...

Simple IF statement
In simple terms i am trying to say if the value in box E2 is "CASH02" or the cell is empty then put "ACTIVE" otherwise put "CLOSED" I have tried many permutations of =if(E2 in ("CASH02", " "),"ACTIVE","CLOSED") I would be grateful if somebody could please correct this. Thank you >=if(E2 in ("CASH02", " "),"ACTIVE","CLOSED") Try it like this... =IF(OR(E2="CASH02",E2=""),"ACTIVE","CLOSED") Or... =IF(OR(E2={"CASH02&qu...