473,387 Members | 1,757 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.

Returning two database fields from a single function call

chandru8
145 100+
hi all
is it possible to return 2 values in a function

iam calling query_execute function
Expand|Select|Wrap|Line Numbers
  1.  xlSht.Cells(7, Cols) = Query_Execute1(q, c)
  2.  
  3. Public Function Query_Execute1(q, c)
  4.  
  5.         Dim Rs As Recordset
  6.         Dim sSql As String
  7.  
  8.         Set db = CurrentDb()
  9.  
  10.         sSql = "SELECT Sum(txbal.DEBIT_NO) AS SumOfDEBIT_NO, Sum(txbal.DEBIT_AMOUNT) AS SumOfDEBIT_AMOUNT"
  11.         sSql = sSql + " FROM (txbal INNER JOIN TRXNTYPE ON txbal.TRXN_CODE = TRXNTYPE.TRXNCODE) INNER JOIN CARD_TYPE ON txbal.CARD_TYPE = CARD_TYPE.CARD_TYPE"
  12.         sSql = sSql + " WHERE (((CARD_TYPE.PROVIDER)='visa') AND ((CARD_TYPE.TYPE)='classic') AND ((txbal.TRXN_CODE)= 40) and ((txbal.TRXN_TYPE)='D E B I T S' Or (txbal.TRXN_TYPE)='C R E D I T S') AND ((CARD_TYPE.PRODUCT) = '" & q & "' ));"
  13.         MsgBox sSql
  14.         Set Rs = db.OpenRecordset(sSql)
  15.  
  16.         Query_Execute1(q, c) = Rs.Fields(0) 
  17.  
  18.     End Function
  19.  
i need to return rs.fields(0) and rs.fields(1)

is it possible or not
Oct 4 '07 #1
3 1458
MikeTheBike
639 Expert 512MB
hi all
is it possible to return 2 values in a function

iam calling query_execute function

xlSht.Cells(7, Cols) = Query_Execute1(q, c)

Public Function Query_Execute1(q, c)

Dim Rs As Recordset
Dim sSql As String

Set db = CurrentDb()

sSql = "SELECT Sum(txbal.DEBIT_NO) AS SumOfDEBIT_NO, Sum(txbal.DEBIT_AMOUNT) AS SumOfDEBIT_AMOUNT"
sSql = sSql + " FROM (txbal INNER JOIN TRXNTYPE ON txbal.TRXN_CODE = TRXNTYPE.TRXNCODE) INNER JOIN CARD_TYPE ON txbal.CARD_TYPE = CARD_TYPE.CARD_TYPE"
sSql = sSql + " WHERE (((CARD_TYPE.PROVIDER)='visa') AND ((CARD_TYPE.TYPE)='classic') AND ((txbal.TRXN_CODE)= 40) and ((txbal.TRXN_TYPE)='D E B I T S' Or (txbal.TRXN_TYPE)='C R E D I T S') AND ((CARD_TYPE.PRODUCT) = '" & q & "' ));"
MsgBox sSql
Set Rs = db.OpenRecordset(sSql)

Query_Execute1(q, c) = Rs.Fields(0)

End Function

i need to return rs.fields(0) and rs.fields(1)

is it possible or not
Hi

Four things

1. Does this functionn actualy run ? I think this
Query_Execute1(q, c) = Rs.Fields(0)
should be
Query_Execute1 = Rs.Fields(0)
or more simply
Query_Execute1 = Rs(0)

2. Argument c is not used in the function (unless I've missed it)

3. I would use an ampersand (&) for string concatenation not + which will add numbers.

4. To my knowlege a function only return one value. It's also good practice to declare the function and argument types ie
Public Function Query_Execute1(ByVal q as String, ByVal c as string) as Long

You do not say how you want to use these two 'values' but if you want to add the two together in a cell then
Query_Execute1 = Rs(0) + Rs(1)

If you want to display the two values in one cell then declare the function as string and this
Query_Execute1 = Rs(0) & " " & Rs(1)
will display the values with a space.

Only guessing here but any good??

Failing this you can pass then back to the calling code as arguments (ByRef) but then you can use a sub to do this instead of a function (unless you use the function to verify that the query has executed - but that is another question/technique).

MTB
Oct 4 '07 #2
Killer42
8,435 Expert 8TB
Ignore me. Just registering an interest, as I'd like to see where this thread goes.
Oct 5 '07 #3
pbmods
5,821 Expert 4TB
Heya, Chandru.

Changed thread title to better describe the problem (did you know that threads whose titles do not follow the Posting Guidelines actually get FEWER responses?).

Please use CODE tags when posting source code:

[CODE=vb]
VB code goes here.
[/CODE]
Oct 17 '07 #4

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

Similar topics

4
by: Jim in Arizona | last post by:
I'm wanting to do a simple controlled voting page. I too our webserver off anonymous and everyone who accesses the website is a domain authenticated user. I've already done some control structure...
4
by: Roger Redford | last post by:
Dear Experts, I'm attempting to marry a system to an Oracle 817 datbase. Oracle is my specialty, the back end mainly, so I don't know much about java or javascript. The system uses javascript...
7
by: RCS | last post by:
Okay, a rather 'interesting' situation has arisen at a place I work: I need to convert a database from Access to something that can be used over the web. I am currently maintaining and...
2
by: Simon Pleasants | last post by:
Am something of a newbie at this, so please bear with any stupid questions. I have created a database to track shipments that we import. The information is stored in a table and I have created...
6
by: lenny | last post by:
Hi, I've been trying to use a Sub or Function in VBA to connect to a database, make a query and return the recordset that results from the query. The connection to the database and the query...
3
by: Khurram | last post by:
Hi, Firstly, I will apologise now if I have posted in the wrong discussion group. Please let me know if I have for future reference. Below is the code to a WebMethod that is querying an Access...
47
by: Jo | last post by:
Hi there, I'm Jo and it's the first time I've posted here. I'm in process of creating a database at work and have come a little unstuck.....I'm a bit of a novice and wondered if anyone could...
0
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me...
160
by: DiAvOl | last post by:
Hello everyone, Please take a look at the following code: #include <stdio.h> typedef struct person { char name; int age; } Person;
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
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
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...

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.