473,651 Members | 3,090 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding Different Fields

Say I have to different recordsets that have the fields:
rsA.Fields.Item ("A").Value ,rsB.Fields.Ite m("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 1579
test them first :

If Not IsNull(fielda) and Not IsNull(fieldb) then ....
"Mangler" <dw******@aspde vil.comwrote in message news:11******** *************@p 10g2000cwp.goog legroups.com...
Say I have to different recordsets that have the fields:
rsA.Fields.Item ("A").Value ,rsB.Fields.Ite m("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.Fiel ds.Item("price" ).Value) and Not
IsNull(rsRef.Fi elds.Item("pric e").Value) Then Response.Write
rsR.Fields.Item ("price").Va lue + rsRef.Fields.It em("price").Val ue 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.Ite m("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******@aspde vil.comwrote in message news:11******** **************@ q2g2000cwa.goog legroups.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.Fiel ds.Item("price" ).Value) and Not
IsNull(rsRef.Fi elds.Item("pric e").Value) Then Response.Write
rsR.Fields.Item ("price").Va lue + rsRef.Fields.It em("price").Val ue 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.Ite m("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("Quan tity").Value || 0
rs.Fields("Addr ess2").Value || ""
rs.Fields("Vali dated").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...@s pammotel.com>
wrote:
rs.Fields("Quan tity").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
4881
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 cmdAdd_Click() On Error GoTo AddErr DatPrimaryRS.Recordset.MoveLast DatPrimaryRS.Recordset.AddNew DatPrimaryRS.Recordset.Fields("Caller").Value = txtCaller.Text DatPrimaryRS.Recordset.Fields("Date").Value = txtDate.Text
5
3739
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 Office 2000. I am creating a database to track student athletes. I have created the following tables. The table title is to the far left, with fields under each. The common field will be the StudentID field, which is their student number assigned...
2
5780
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 new record to a subform. If I close msgbox I can then successfully add new record. Have looked on MS Technet and tried their 2 suggestions:- 1)LinkChildFields property contains the name of a form property - this isn't the case linkChildFields...
5
1506
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 different loops. My output comes out to be as Follows: TABLE ---------------------------------------------------- Field1 Field2
2
3199
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 different loops. My output comes out to be as Follows: TABLE ----------------------------------------------------
0
1447
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 with all the fields I
5
5355
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: and from here I go to the end (because the other part is in an If statement and that's in a loop...once the loop's finished, I've gathered the necessary information I would paste the full function but I already have in another place on this site and...
5
2310
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 fields are default value = 0 on the table and on the form. Fields are filled in at different times and maybe by different people, so I wanted them all to "initialize" to 0.
18
1965
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 decrement it to the current quantity for example if tehre is a part woth part no 10023 and its quantity in show room is 20 and total quantity is 25 then if there is a sale of 2 parts then i have to add the sale and decrement the current quantity in the...
0
8361
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8278
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8807
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8466
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8584
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7299
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5615
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4290
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2701
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 we have to send another system

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.