Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access VBA - Returning some sort of blank/null for function declared as long

Question: I want to use a VBA function in Access that is declared as type Long. I want to return an integer between 0 and 35 some of the time, but I also want to be able to return a blank or null or something like that most of the time. Is there a way to do this? What I have tried (variable = "" or Set variable = Nothing) just calls an error. This will be used in a query and will give the value for one column. I want that column to be type Long. If such a thing is not possible, I guess that is all I need to know, as I already have a different but less desirable solution. Thanks for any help.

Update: Of course, right after asking the question, I figured out a good solution. If I just do Range("whatever").Value = Range("whatever").Value in Excel, then it changes a left aligned 20 to a right aligned 20, at which time it is recognized by the pivot table as a number (though when I just convert the cell type to a number in Excel, it is not recognized as a number in the pivot table). So, I am deleting the background because it is not necessary. I am still interested to know if you can return some sort of blank or null for a function declared as long. Thanks

like image 703
GeoffDS Avatar asked Jan 15 '23 21:01

GeoffDS


2 Answers

Null can only be returned from a Variant function.
Nothing can only be returned from an Object function.

All others, you are restricted to returning a variable of the type defined as the return value of your function.
If you do not set a value, then it returns the default value
A numeric variable is initialized to zero
A variable length string is initialized to a zero-length string ("")
A fixed length string is filled with the ASCII code 0.
A date/time variable is initialized to zero

like image 198
SeanC Avatar answered Jan 30 '23 20:01

SeanC


Since an unitialized long has a value of 0, the answer is "no." A function declared as long cannot return null or blank. If zero wasn't a valid return value for your function, you could use it a "null" equivalent, but you already knew that :)

like image 33
Doug Glancy Avatar answered Jan 30 '23 20:01

Doug Glancy