VBA Code to Add function while retrieving data to Excel

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pkj7461
    New Member
    • Oct 2007
    • 15

    VBA Code to Add function while retrieving data to Excel

    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.
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by pkj7461
    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:
    [CODE=sql]'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 fCalculateWeekD ay() Function and displayed as a [WeekDay_Born] Field
    SELECT tblTest.LastNam e, tblTest.FirstNa me, tblTest.DOB, fCalculateWeekD ay([DOB]) AS WeekDay_Born
    FROM tblTest;[/CODE]

    Comment

    • pkj7461
      New Member
      • Oct 2007
      • 15

      #3
      Originally posted by ADezii
      Create a Public Function in a Standard Code Module and call it directly in an SQL Statement as in:
      [CODE=sql]'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 fCalculateWeekD ay() Function and displayed as a [WeekDay_Born] Field
      SELECT tblTest.LastNam e, tblTest.FirstNa me, tblTest.DOB, fCalculateWeekD ay([DOB]) AS WeekDay_Born
      FROM tblTest;[/CODE]
      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:DateDiff W([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.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32634

        #4
        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.

        Comment

        Working...