473,395 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

New to Code - Syntax for Running a Sub or Function

Hi -
Maybe it's my code, or maybe it's that I am not coding the Call to a
sub in my code properly.

Whichever, I am getting the error "Invalid Use of Null" when running
this code. I do see my first MsgBox "Before Import data statement"
and my Second one: "Imported data 10A, 10B, 11, 12,6A, 6B, 3C for " &
[SaleDate]
but in the middle I get the "Invalid Use of Null Message". Once I say
OK to that, I get the Second message.

I never get the MsgBox in the code I want to execute, so I'm figuring
I never get there - maybe my "Call" is wrong?

I tried moving the Dim statement to the top of the sub, but I still
get the message. I am guessing the Dim statement can be anywhere in
the code, right?

' -----------------------------------------------------------------------------
' OPTION 5 - IMPORT DATA
' ------------------------------------------------------------------------------
If (Me!grpReportList = 5) Then

' Import Data

Dim SaleDate As Date

MsgBox "Before Import data statement"

Import10A

SaleDate = Me.getSaleDate

MsgBox "Imported data 10A, 10B, 11, 12,6A, 6B, 3C for " &
[SaleDate]

End If

(This is the 5th of 6 options. All the others work fine)

'------------------------------------------------------------
' Import Data
' When the user Chooses Opt 5 - Import data
'------------------------------------------------------------

Sub ImportData()
On Error GoTo ImportData_Err

MsgBox "Enter Import Data"
Dim strImportFileName As String

Dim SaleDate As Date
SaleDate = Me.getSaleDate

' for debugging
MsgBox "Saledate from Sub 10A " & SaleDate

'------------------------------------------------------------
' POS10A - Store Sales T:StoreSalesData
'------------------------------------------------------------

strImportFileName = Format([SaleDate], "mm-dd-yy") & " POS10A" &
".xls"

MsgBox strImportFileName

' DoCmd.TransferSpreadsheet acImport, 8, "T:Store Sales Data", _
' "Server-01\Building19\ProductionImports\" &
strImportFileName, True, ""

DoCmd.TransferSpreadsheet acImport, 8, "T:Store Sales Data", _
"C:\TestAutoImport\" & strImportFileName, True, ""

(There are several more files to import; then Error and End Sub)

My code compiles, too.
Thanks so much. I was feeling quite good about getting this far, but
that is fading fast!

Sara
Nov 13 '05 #1
2 1541
Sara, it's kind of tough to say for sure from the little bit of code you've
posted. Your code calls a Sub called Import10A, but the only Sub in your
post is called ImportData. The error might be in Sub Import10A or, more
likely, Me.getSaleDate is Null (just a guess). As a Date data type,
SaleDate can not contain a Null value. If there is a chance that
Me.getSaleDate might be Null, your code should test for that and handle it
appropriately. Not a solution, but a simple test - change SaleDate to a Var
data type, see if the error changes.

HTH,
Randy
"Sara" <sa******@yahoo.com> wrote in message
news:d4*************************@posting.google.co m...
Hi -
Maybe it's my code, or maybe it's that I am not coding the Call to a
sub in my code properly.

Whichever, I am getting the error "Invalid Use of Null" when running
this code. I do see my first MsgBox "Before Import data statement"
and my Second one: "Imported data 10A, 10B, 11, 12,6A, 6B, 3C for " &
[SaleDate]
but in the middle I get the "Invalid Use of Null Message". Once I say
OK to that, I get the Second message.

I never get the MsgBox in the code I want to execute, so I'm figuring
I never get there - maybe my "Call" is wrong?

I tried moving the Dim statement to the top of the sub, but I still
get the message. I am guessing the Dim statement can be anywhere in
the code, right?

' --------------------------------------------------------------------------
--- ' OPTION 5 - IMPORT DATA
' --------------------------------------------------------------------------
---- If (Me!grpReportList = 5) Then

' Import Data

Dim SaleDate As Date

MsgBox "Before Import data statement"

Import10A

SaleDate = Me.getSaleDate

MsgBox "Imported data 10A, 10B, 11, 12,6A, 6B, 3C for " &
[SaleDate]

End If

(This is the 5th of 6 options. All the others work fine)

'------------------------------------------------------------
' Import Data
' When the user Chooses Opt 5 - Import data
'------------------------------------------------------------

Sub ImportData()
On Error GoTo ImportData_Err

MsgBox "Enter Import Data"
Dim strImportFileName As String

Dim SaleDate As Date
SaleDate = Me.getSaleDate

' for debugging
MsgBox "Saledate from Sub 10A " & SaleDate

'------------------------------------------------------------
' POS10A - Store Sales T:StoreSalesData
'------------------------------------------------------------

strImportFileName = Format([SaleDate], "mm-dd-yy") & " POS10A" &
".xls"

MsgBox strImportFileName

' DoCmd.TransferSpreadsheet acImport, 8, "T:Store Sales Data", _
' "Server-01\Building19\ProductionImports\" &
strImportFileName, True, ""

DoCmd.TransferSpreadsheet acImport, 8, "T:Store Sales Data", _
"C:\TestAutoImport\" & strImportFileName, True, ""

(There are several more files to import; then Error and End Sub)

My code compiles, too.
Thanks so much. I was feeling quite good about getting this far, but
that is fading fast!

Sara

Nov 13 '05 #2

Randy -

Many thanks! That was it. Admittedly I'm a little embarrassed, but
more thankful than embarrassed. I work in a small family business and am
the only person doing Access (or anything with PCs or code, really -
most don't even do email yet). There is no one to ask to look over my
code to spot these obvious errors - the user groups are great!

Surely I'll "talk" to you again soon.

Ever grateful,
Sara

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: Delta | last post by:
Drop Down Menu Mozilla : work well widowed elements such as drop downs, except for flash movies IE : work well so far http://pwp.netcabo.pt/falmartins/index.htm
8
by: Paul Cochrane | last post by:
Hi all, I've got an application that I'm writing that autogenerates python code which I then execute with exec(). I know that this is not the best way to run things, and I'm not 100% sure as to...
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
15
by: Kevin Hanken | last post by:
Hi, Pretty much a newbie to aspnet and xp -- I am using XP Pro, Service Pack 2. I installed IIS, set up a virtual directory, created an aspx file and pasted in a little code from the w3schools...
27
by: David Golightly | last post by:
This is just a quick poll for all you web devs out there: What browsers do you test on/are concerned about compatibility with? Obviously, you're going to test on current-generation browsers such...
2
by: ApexData | last post by:
Hi I am using the Shortcut Menu Bar property of a control to specify a Custom popupmenu that displays when the right-click of the mouse is used. Can I place some kind of command in this...
8
by: boki_pfc | last post by:
Hi Everybody, I am looking for an advice on following: I have that "pleasure" of reading C++ codes that have been written by person(s) that have not attended the same C++ classes that I did or...
27
by: Dave | last post by:
I'm having a hard time tying to build gcc 4.3.1 on Solaris using the GNU compilers. I then decided to try to use Sun's compiler. The Sun Studio 12 compiler reports the following code, which is in...
3
by: tokcy | last post by:
Hi everyone, I have class and whenever i am running to this class it shows error like Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.