473,387 Members | 1,517 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,387 software developers and data experts.

ADO AddNew problem

Hi everyone,

I've got an ADO AddNew update query in VBA. Some of the fields may be
empty and I want to know if there is an easier way than writing If
statements around each field to test for null.

Here's my code

.AddNew ' create a new record
' add values to each field in the record
.Fields("fkRSCWeekID") = Range("AA" & r).Value
.Fields("fkPrimeID") = Range("R" & r).Value
.Fields("fkTypeID") = Range("S" & r).Value

For example, right now if the first field (fkRSCWeekID) is blank it
throws a Type Mismatch error. Can anyone please advise how I can run
the update regardless of whether the field is populated or not?

Thanks in advance,

Jeff

Nov 9 '06 #1
2 2839

Jeff,

You should probably set up default values on your table fields. Both
access and sql server support default values. Other than that, I am
not sure there is an easy way. Even using the IIF() function can be
tedious if you have many fields with the potential to be null.

Hope this helps,

Brian
an**********@gmail.com wrote:
Hi everyone,

I've got an ADO AddNew update query in VBA. Some of the fields may be
empty and I want to know if there is an easier way than writing If
statements around each field to test for null.

Here's my code

.AddNew ' create a new record
' add values to each field in the record
.Fields("fkRSCWeekID") = Range("AA" & r).Value
.Fields("fkPrimeID") = Range("R" & r).Value
.Fields("fkTypeID") = Range("S" & r).Value

For example, right now if the first field (fkRSCWeekID) is blank it
throws a Type Mismatch error. Can anyone please advise how I can run
the update regardless of whether the field is populated or not?

Thanks in advance,

Jeff
Nov 9 '06 #2
.AddNew ' create a new record
' add values to each field in the record
.Fields("fkRSCWeekID") = NZ(Range("AA" & r).Value , "")
.Fields("fkPrimeID") = NZ(Range("R" & r).Value , "")
.Fields("fkTypeID") = NZ(Range("S" & r).Value, "")

Try that and see if it works for you.
Chris Nebinger
an**********@gmail.com wrote:
Hi everyone,

I've got an ADO AddNew update query in VBA. Some of the fields may be
empty and I want to know if there is an easier way than writing If
statements around each field to test for null.

Here's my code

.AddNew ' create a new record
' add values to each field in the record
.Fields("fkRSCWeekID") = Range("AA" & r).Value
.Fields("fkPrimeID") = Range("R" & r).Value
.Fields("fkTypeID") = Range("S" & r).Value

For example, right now if the first field (fkRSCWeekID) is blank it
throws a Type Mismatch error. Can anyone please advise how I can run
the update regardless of whether the field is populated or not?

Thanks in advance,

Jeff
Nov 9 '06 #3

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

Similar topics

9
by: Jan van Veldhuizen | last post by:
I have an application which is running fine with MS SqlServer, but it should be working with Oracle as weel. At a lot of places we rely upon the ADO Recordset to return incremented identity...
1
by: Jon Trelfa | last post by:
I have been fighting with this script for several days and I'm finally at the end of my rope. Here's the scenario: -I have to add an entry into 1 table, called "calendar" -I must retrieve the...
25
by: dixie | last post by:
I have some code that adds new records into a table for each ID in a list box when a button on a form is clicked. This works fine. My problem now is that I wish to be able to edit all the records...
5
by: Mika M | last post by:
Hello! I have Windows Forms application form containing TextBoxes, six ComboBoxes, and DataGrid for details. I have created DataSet with needed tables, and created relations between tables, and...
6
by: Aaron Smith | last post by:
I have a form, oddly enough the same one with the expression column that is giving me a headache, and on this form I have a dataset that has a couple of tables in it that are related. If I do a...
1
by: Leonardo | last post by:
Hi. I'm trying to build my first application with database access using VB 2005. I'm a VB 6 programmer and learning everything again has been challenging. I managed to write a code using some tips...
1
by: teenagelcruise | last post by:
hi, i have a problem with my code which is i cannot update and addnew data into the database but i can delete the data.plz give me an idea.this is my code that i wrote. <html> <head> <meta...
0
nev
by: nev | last post by:
Have any of you encountered this? And how did you correct it? bs.addnew() automatically moves the position to the new record. But mine doesn't. I have 3 bindingsources in my program, all...
4
by: mayen001 | last post by:
Hi First time i am posting a question so here goes... I have created a bit of VBA for pupils where the aim is: input line of text from file;parse the input line and extract values; using the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.