473,398 Members | 2,404 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,398 software developers and data experts.

Adding Different Fields

Say I have to different recordsets that have the fields:
rsA.Fields.Item("A").Value ,rsB.Fields.Item("B").Value

How would I add those to fields? It may be my inexperience but when I
tried something like

rsA.Fields.Item("A").Value + rsB.Fields.Item("B").Value

didnt work because one of the fields was a empty value. I have about
6 fields i need to add together if a value exists in any of them.

Suggestions?

Respectfully,

Danny

Jan 30 '07 #1
6 1574
test them first :

If Not IsNull(fielda) and Not IsNull(fieldb) then ....
"Mangler" <dw******@aspdevil.comwrote in message news:11*********************@p10g2000cwp.googlegro ups.com...
Say I have to different recordsets that have the fields:
rsA.Fields.Item("A").Value ,rsB.Fields.Item("B").Value

How would I add those to fields? It may be my inexperience but when I
tried something like

rsA.Fields.Item("A").Value + rsB.Fields.Item("B").Value

didnt work because one of the fields was a empty value. I have about
6 fields i need to add together if a value exists in any of them.

Suggestions?

Respectfully,

Danny

Jan 30 '07 #2


On Jan 30, 11:49 am, "Jon Paal" <Jon nospam Paal @ everywhere dot com>
wrote:
test them first :

If Not IsNull(fielda) and Not IsNull(fieldb) then ....
Tried this, maybe i am wrong here:

<% If Not IsNull(rsR.Fields.Item("price").Value) and Not
IsNull(rsRef.Fields.Item("price").Value) Then Response.Write
rsR.Fields.Item("price").Value + rsRef.Fields.Item("price").Value End
If %>

Keep getting a mismatch error...

Jan 30 '07 #3
Mangler wrote:
Say I have to different recordsets that have the fields:
rsA.Fields.Item("A").Value ,rsB.Fields.Item("B").Value

How would I add those to fields? It may be my inexperience but when I
tried something like

rsA.Fields.Item("A").Value + rsB.Fields.Item("B").Value

didnt work because one of the fields was a empty value. I have about
6 fields i need to add together if a value exists in any of them.
1. Modify the sql statements that produce the recordset to ensure the
fields do not contain Nulls. The details depend on the database you are
using. For example, SQL Server has the COALESCE function that can be
used to return either the value, or 0 if the value is Null.
2. Assign the values to variables (GPB*), check to see if they have
values and, if not, set them to 0 (zero) before adding them
*Good Programming Practice

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jan 30 '07 #4
Type mismatch is a general error that happens when you try to stuff one type of value into a variable of another type.

Let's say you are working with numbers, adding and subtracting them. You're working with

LowVal
HighVal
NewVal

And then at some point you say something like

HighVal = "XYZZY"

your operations are soon going to fail with a type mismatch error.



The easiest way to figure out where you went wrong is to do a response.write of each value along the path. That way you can see
exactly what each value is set to, and figure out which one is getting in a "bad" value.
"Mangler" <dw******@aspdevil.comwrote in message news:11**********************@q2g2000cwa.googlegro ups.com...
>

On Jan 30, 11:49 am, "Jon Paal" <Jon nospam Paal @ everywhere dot com>
wrote:
>test them first :

If Not IsNull(fielda) and Not IsNull(fieldb) then ....
Tried this, maybe i am wrong here:

<% If Not IsNull(rsR.Fields.Item("price").Value) and Not
IsNull(rsRef.Fields.Item("price").Value) Then Response.Write
rsR.Fields.Item("price").Value + rsRef.Fields.Item("price").Value End
If %>

Keep getting a mismatch error...

Jan 30 '07 #5
Mangler wrote:
Say I have to different recordsets that have the fields:
rsA.Fields.Item("A").Value ,rsB.Fields.Item("B").Value

How would I add those to fields? It may be my inexperience but when I
tried something like

rsA.Fields.Item("A").Value + rsB.Fields.Item("B").Value

didnt work because one of the fields was a empty value. I have about
6 fields i need to add together if a value exists in any of them.

Suggestions?
SQL ISNULL is a good choice to ensure you always have a value in your field:
http://msdn2.microsoft.com/en-us/lib...0(SQL.80).aspx

It is also worth pointing out that JScript conditional assignment makes this
quite trivial:

(rsA.Fields("A").Value || DEFAULT_VALUE) + ...

You have to set your default value according to type, of course. For
example:

rs.Fields("Quantity").Value || 0
rs.Fields("Address2").Value || ""
rs.Fields("Validated").Value || false

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Jan 30 '07 #6
On Jan 30, 12:44 pm, "Dave Anderson" <NYRUMTPEL...@spammotel.com>
wrote:
rs.Fields("Quantity").Value || 0
I tried assigning the defult value like the above example and kept
getting an error saying invalid character. I did however get what I
need done to work. Just put some hidden fields with the recordset as
the value and called a javascript function to add the fields.

Jan 31 '07 #7

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

Similar topics

0
by: Steve Z | last post by:
Some guidance por favor I started this program with the Data Form Wizard (never again). I'm pretty deep into it now, this piece of code keeps overwriting the first record in the DB: Private Sub...
5
by: Sami | last post by:
Please bear with me, and if you answer this question, please do it step by step. I am new at Access, not at all sophisticated. I am using Office XP. This will need to be read in Access for...
2
by: brenda.stow | last post by:
error msg " An error occured while referencing the object. You tried to run a visual basic procedure that improperly references a property or method of an object" This msg occurs everytime I add a...
5
by: Justin Fancy | last post by:
Hi everyone, I need some help. I'm placing text files into a created database using vb.Net. The problem is that, i need two seperate sql statements to add both files because they are in...
2
by: Justin Fancy | last post by:
Hi everyone, I need some help. I'm placing text files into a created database using vb.Net. The problem is that, i need two seperate sql statements to add both files because they are in...
0
by: AboutJAV | last post by:
I created a crystal report with the report.rpt reportdata.xsd I created the a new dataset with the reportdata myreportdata = new reportdata(); That automatically created a new dataset...
5
by: Kosmos | last post by:
I have traveled the world and the seven seas and I have yet to come up with an answer to this question.... So I'm adding an attachment to an email from access... The following is the code: ...
5
by: sara | last post by:
Hi - I have 2 new questions in a new database I'm trying to develop. The first has 6 fields on a table and allows the user to enter them on a form. The form is bound to the table. All 6...
18
omerbutt
by: omerbutt | last post by:
AJAX PROB WITH MULTIPLE RECORDS helo iam having problem in ma code will any body look out an help, i am trying t add sale record in the database and the checkthe quantity of the part slod and...
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
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.