Posts by Mattheq

    Re: MDX Return min value (excluding empty and 0)


    Hello.


    You can run a nested query. First query returns all non-zero data. Second query returns minimum value in the first query.


    Assuming your table is called "myTable" and the field of interest is "MinOrder", the following example should achieve what you are looking for.


    Code
    select Min([myValue]) from (select MinOrder as [myValue] from myTable where MinOrder > 0)


    This should return the minimum value for all days where your orders are above zero.



    Hope this helps.

    Re: Access Populate YTD & 3 Month Total Column


    Hello.


    Populate the required fields with a query.


    SELECT Year, Month, UPC, Sum(Dollars) AS SumOfDollars, Sum(Units) AS SumOfUnits
    FROM MyTable
    GROUP BY Year, Month, UPC
    HAVING (((Year)=2014));


    If you want to summarise over a three month period, you can add a Month criteria to add this level of summary.



    Hope this helps.

    Re: Export Excel sheet directly to MSSQL using script


    Hello Barry,


    If it's a stored procedure (as indicated by the OP), it will be a query (or SQL View) saved on the SQL server itself that returns a recordset. Without knowing more about the database or the stored procedure itself, I can't be clearer that that.


    Presumably the stored procedure doesn't have any parameters (variable fields or constraints) associated with it, as the OP has not appended these in the code.


    Hope this helps.

    Re: Can Access VBA create table with more than 33 fields?


    Hello,


    I was able to run the query after editing the data type for your 33rd field. It may be as simple as a typo where your field data type is "TXT" instead of "TEXT".


    No issues with running this on Access 2010. Which version of Access are you using?



    Hope this helps.

    Re: Is there VBA code to reference an array of worksheet names to a list?


    Hello,


    I think there are a number of ways you could achieve your goal:


    1. Create a Table of Contents worksheet within your workbook by following the code in this article http://blogs.office.com/2011/0…e/?utm_source=twitterfeed Then follow your original code idea of scrolling through the worksheet for all worksheet names.




    2. Loop through the sheets in your workbook and exclude the data source and chart sheets from your code



    Hope this helps.

    Re: In VBA Excel Using a subroutine argument to pass on to VLookup to make it genera


    Hello again,


    I understand that your TableX variable is returning the value "Table2".


    This formula:

    Code
    .Range(Cells(intTHRow + 1, iEmptCol), Cells(35, iEmptCol)).Formula = "=VLOOKUP(TableX[@Ticker],Table1,3,FALSE)"


    is not incorporating the variable, which is why you need to change the code to the example shown in my previous post.


    For instance, if I had code that writes a formula to cells in different rows, I would use something like:


    Code
    Dim i As Integer
    
    
    For i = 1 To 10
        Cells(i, 1) = "This is row " & i
    Next


    Your code is more like the following example:


    Code
    Dim i As Integer
    
    
    For i = 1 To 10
        Cells(i, 1) = "This is row i"
    Next

    Re: In VBA Excel Using a subroutine argument to pass on to VLookup to make it genera


    Hello,


    it looks like you're not passing the variable to the formula.


    Try replacing this line of code:

    Code
    .Range(Cells(intTHRow + 1, iEmptCol), Cells(35, iEmptCol)).Formula = "=VLOOKUP(TableX[@Ticker],Table1,3,FALSE)"


    with this:

    Code
    TableX = "Table2" 'TableX should be a string variable
    .Range(Cells(intTHRow + 1, iEmptCol), Cells(35, iEmptCol)).Formula = "=VLOOKUP(" & TableX & "[@Ticker],Table1,3,FALSE)"


    Hope this helps

    Re: Export Excel sheet directly to MSSQL using script


    Hello ikith,


    I presume you checked the presence of the "headcountstest" stored procedure? This looks to be the first place to start. Make sure you haven't spelled it incorrectly, and remove the "dbo." from within your VBA.


    Hope this helps.

    Re: SQL Not Like and handle blanks


    Hello Smithy7876,


    I replicated your table as much as I could given the information and came up with the following SQL table:


    [TABLE="width: 500"]

    [tr]


    [td]

    Field Name

    [/td]


    [td]

    Data Type

    [/td]


    [td]

    Allow Nulls

    [/td]


    [/tr]


    [tr]


    [td]

    ProjID

    [/td]


    [td]

    float

    [/td]


    [td]

    No

    [/td]


    [/tr]


    [tr]


    [td]

    FolderName

    [/td]


    [td]

    nvarchar(50)

    [/td]


    [td]

    No

    [/td]


    [/tr]


    [tr]


    [td]

    EntityCode

    [/td]


    [td]

    nvarchar(50)

    [/td]


    [td]

    No

    [/td]


    [/tr]


    [tr]


    [td]

    ParentName

    [/td]


    [td]

    nvarchar(50)

    [/td]


    [td]

    Yes

    [/td]


    [/tr]


    [tr]


    [td]

    IsActive

    [/td]


    [td]

    nchar(10)

    [/td]


    [td]

    No

    [/td]


    [/tr]


    [/TABLE]



    Populating this table with the sample data you provided, I ran the query shown below:


    SQL
    SELECT        ProjID, EntityCode, ParentName
    FROM            dbo.Folders
    WHERE        (EntityCode = 'TestCases') AND (ParentName IS NULL OR NOT (ParentName LIKE '%/%'))


    Results from the query were as follows:


    [TABLE="width: 500"]

    [tr]


    [td]

    ProjID

    [/td]


    [td]

    EntityCode

    [/td]


    [td]

    ParentName

    [/td]


    [/tr]


    [tr]


    [td]

    11888

    [/td]


    [td]

    TestCases

    [/td]


    [td]

    NULL

    [/td]


    [/tr]


    [tr]


    [td]

    11888

    [/td]


    [td]

    TestCases

    [/td]


    [td]

    Level 1

    [/td]


    [/tr]


    [/TABLE]



    Hope this helps

    Re: Display message box if cell value changes....


    Hello Varun,


    Have you considered a Worksheet Change event?


    Re: Access Database vba method to return table field names



    This methodology works for me (syntax not tested, please check before using)


    strSQL = "select * from Table"


    Open the recordset.


    Code
    for i = 0 to rst.field.count -1
    
    
    Fieldarray(i) = rst.field(i).name
    
    
    next


    close recordset.

    Re: Update multiple records in access from Excel also close access when done


    Hello.


    Do you specifically need Access to be open to do this? If not you can just open a connection and update the table using an update statement. You need to add a reference to Microsoft ActiveX Data Objects 2.8 Library for this solution (if you haven't already added it). This solution does not require the access database to open at all (only a connection to it).




    Hope this helps.

    Re: Explaination Needed


    A bit of quick playing around with recording macros yields the following:


    Re: Accessing SQL using VBA Code


    Hello do0bee,


    Where does the code fail? I suspect it's the formation of your command text. Clarify your string with spaces after the commas in the select part, and format your date correctly. YOu also don't need to specify the database (catalog) in the FROM clause, as that is set in your connection string. Try the following and let me know if it works for you.


    Code
    SQL_String = "SELECT date, agreement_type_id, cpe_id, shaw_entity_family_id, margin_usd FROM yak_interim_excess_deficit WHERE date = '01-05-2013' AND strategy_id = 1760076"


    Hope this helps.

    Re: Query using OraOLEDB with WHERE and BETWEEN


    Hello Maria,


    You are missing an ' in the end date in the code you posted. Could be as simple as that.


    Code
    'Select EmpassignHist table, enter query string
    cmd.CommandText = "SELECT * FROM DB.TableRef WHERE field BETWEEN '01-03-2013' AND '03-03-2013'"



    If that doesn't resolve your issue, try encapsulating the WHERE criteria in brackets.

    Code
    'Select EmpassignHist table, enter query string
    cmd.CommandText = "SELECT * FROM DB.TableRef WHERE (field BETWEEN '01-03-2013' AND '03-03-2013')"


    You may also need to format your date to the appropriate format. Some queries can go awry due to this whereby day and month parts of the dates can be transposed (3 January or 1 March for your start date?) You can do this using the following example to ensure you know exactly what format the dates will return:


    Code
    'Select EmpassignHist table, enter query string
    cmd.CommandText = "SELECT * FROM DB.TableRef WHERE (field BETWEEN '" & format(dateStart, "MM/dd/yyyy HH:mm") & "' AND '" & format(dateEnd, "MM/dd/yyyy HH:mm") & "')"




    Hope this helps.

    Re: Duplicate Command Buttons on different Worksheets


    Steve,

    Try something like this:

    Code
    Application.ScreenUpdating = False
     
    'Your existing code goes here
    'You will want error trapping to make sure that screen updating is true if your code breaks.
     
    Application.ScreenUpdating = True



    This should prevent your users from seeing a flickering screen.

    Hope this helps.