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

VBA Code to Add function while retrieving data to Excel

15
Hi,
I have a column in my Select statement of query that retrievies data based on a Function that is defined in a Module.
Like this: PQRAge: DateDiffW([Create-date],Date()).
This DateDiffW is defined in the module

I am retreiving this data into Excel sheet using ADO.Net.
How do I add the module in my select statement.?
Thank you for your time,
Prasanna.
Oct 20 '07 #1
3 2151
ADezii
8,834 Expert 8TB
Hi,
I have a column in my Select statement of query that retrievies data based on a Function that is defined in a Module.
Like this: PQRAge: DateDiffW([Create-date],Date()).
This DateDiffW is defined in the module

I am retreiving this data into Excel sheet using ADO.Net.
How do I add the module in my select statement.?
Thank you for your time,
Prasanna.
Create a Public Function in a Standard Code Module and call it directly in an SQL Statement as in:
Expand|Select|Wrap|Line Numbers
  1. 'The following SQL Statement will retrieve an individual's Last Name, First Name, Date of Birth, and the Weekday the individual was born on. The Weekday is obtained by passing the [DOB] Argument to the fCalculateWeekDay() Function and displayed as a [WeekDay_Born] Field
  2. SELECT tblTest.LastName, tblTest.FirstName, tblTest.DOB, fCalculateWeekDay([DOB]) AS WeekDay_Born
  3. FROM tblTest;
Oct 20 '07 #2
pkj7461
15
Create a Public Function in a Standard Code Module and call it directly in an SQL Statement as in:
Expand|Select|Wrap|Line Numbers
  1. 'The following SQL Statement will retrieve an individual's Last Name, First Name, Date of Birth, and the Weekday the individual was born on. The Weekday is obtained by passing the [DOB] Argument to the fCalculateWeekDay() Function and displayed as a [WeekDay_Born] Field
  2. SELECT tblTest.LastName, tblTest.FirstName, tblTest.DOB, fCalculateWeekDay([DOB]) AS WeekDay_Born
  3. FROM tblTest;
Hi, This seems to be not working. I am sorry If i haven't explained this properly.
My original select statement in Access retrieves one of the columns through module like this: PQRAge:DateDiffW([Create-date],Date()). This works fine when I add them to the select statement in Access.

However, I am retrieiving the same column with the VBA Code and place them in Excel sheet. The code fills allother data except the PQRAge.
How do I achieve this in VBA Code written in Excel?
Thanks,
prasanna.
Oct 21 '07 #3
NeoPa
32,556 Expert Mod 16PB
I'm not sure that's possible Prasanna. Unfortunately the Excel SQL works via MSQuery rather than Access. It only has access to the basic SQL. You could try (as a long shot) to add a function into your worksheet and see if that is usable from within the query.
Oct 21 '07 #4

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

Similar topics

12
by: Bob Bedford | last post by:
I've a page where users may enter a zip code (text edit) and I want to fill a combobox with existing cities depending on the zip code entered. Let give an example. I've my text edit like:...
2
by: Chris Bellini | last post by:
Greetings! I'm developing a C# application that needs to read some data from a selected XLS file. I've used VB in the past to automate Excel but this is the first time I've used C#. Back in VB,...
1
by: garry.oxnard | last post by:
Can anyone help me to solve a problem which involves switching from Access to Excel (then back to Access) programatically please? I have an Excel template which, on open, also opens an Access...
0
by: coony | last post by:
Hi everyone, I got an annoying thing going on. I've got an MSSQL db which is filled with different data, used by another program (T-Plan). I should read some table to import in another DB. The...
1
by: rrstudio2 | last post by:
I was reading and modifying some VB code needed to import all of the excel files in a directory into one table in Access and ended up with the following which works. Public Sub...
1
by: jainsiddarth | last post by:
Hi experts, I want to retrieve data in excel based on the resources. I have three columns in the excel i.e. task, resource and status. Now tasks are unique and can be assigned to multiple users and...
4
by: drt | last post by:
NEDERLANDS: Hallo, Ik heb eigen functies gemaakt in access, die werken perfect in de access query. Zodra ik echter vanuit excel een draaitabel maakt naar de access query (als een externe...
3
by: keirnus | last post by:
hello, been searching for a solution on this but all i get are advices for importing data from excel directly to MS Access DB. my case here is different...the sheet in Excel file is not ready...
1
by: xia0jie | last post by:
Hi all, Im using the following codes to retrieve records from excel file. OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Path + "; Extended...
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: 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
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
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
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...
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
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...

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.