473,473 Members | 2,155 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

VBA: insert a null into a date field

2 New Member
I have an access database. i am inserting data from an excel worksheet

i have a very long insert (41 columns). in the middle of the pack i have several date fields.
Some of the date fields are null and should be null until the user or batch job updates the access db.

i have defined the following
[CODE}
Dim FirmCommitmentIssued
FirmCommitmentIssued =((Sheets("OD_ASSUMPTIONS").Cells(iRow, iCol + 25).Value))
If Len(FirmCommitmentIssued) = 0 Then
FirmCommitmentIssued =null
End If
[/code]
however, i get an automation error, when this occurs

i know i could write a seperate insert statements and do a check so if null then insert without using this field. but then i would mess up some of the other logic.

is there anyway to insert a null or a default value say 1/1/1900
thanks
Mar 31 '10 #1
1 2753
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi. I suspect that your problem arises not from the null, but from using the Sheets collection without referencing the automation server object you must have defined to run Excel from your Access code.

Within Excel, the application object is implicit - so

Expand|Select|Wrap|Line Numbers
  1. SetSomething = Sheets("SomeSheet") .SomeRange
will be interpreted OK. This is not a reliable method to use in application automation, although it can work for some iterations within looping code (giving the appearance that some condition is occurring within the loop which is causing the error).

When using application automation you MUST refer to the automation server object explicitly. If you have defined a variable called objExcel, say, you must be explicit in linking it to your code referring to the Sheets collection:

Expand|Select|Wrap|Line Numbers
  1. Dim objExcel as Excel.Application
  2. Set objExcel = New Excel.Application
  3. (...)
  4. (...code to open workbook..)
  5. (...)
  6. FirmCommitmentIssued = objExcel.Sheets("OD_Assumptions").Cells(...)
Beware of using or adapting code generated by the Excel macro recorder, as it does not generate explicit references to the application object, and use of its code without consideration of whether or not it is running within Excel or one of the other Office applications can lead to many frustrating hours of error tracing.

-Stewart
Apr 1 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: jason | last post by:
I need to deposit and empty dummy value into a date/time field within Access using INSERT. However, I pick up a data type error if I attempt to insert a NULL value for this particular date time...
0
by: David Bordas | last post by:
Hi list, I've got a little bug with MySQL. I can insert a row into my table but this row will not appear in the table :( Server is under linux redhat, MySQL is 3.23.56 installed from binary...
2
by: keith | last post by:
Thanks to everyone for their previous help, I'm almost finished with my database. I just need one piece of information, and it should be good to go! I'm using a SQL Server database with Access...
6
by: FatboyCanteen | last post by:
When I using dataset to append a null value to the datetime field. It throw a error -> can not convert db.null to system.date Can there is any standard to pass a Null value to the DateTime...
3
by: 4partee | last post by:
I'm trying to import a csv file with a PHP procedure. However, some of the lines in the csv file have missing values. When this command is given to mysql: insert tablex values...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
4
by: Parsa | last post by:
Hello everyone, I have been looking on the net to solve my problem for several days now, but i couldn't find what I was looking for. I'm designing a database for a university and in one of the...
0
chumlyumly
by: chumlyumly | last post by:
Hello scripters - OS: Mac OSX Language: PHP w/ MySQL database I've created an insert page where a user inputs his info, which then goes to four different tables in a MySQL database. The...
8
vs2k8
by: vs2k8 | last post by:
Hello guys, New to this forum and new to access programing, my issue is I am comparing 2 date fields, I have to validate that Order Rcvd Dt should be less then Ord Comp date and Order Comp date...
6
by: ndeeley | last post by:
Hi, How do I insert a null or blank field into a database using coldfusion? I'm new to CF and its proviing a bit tricky! My database date field accepts null values (I think - theres no default...
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
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.