+ Reply to Thread
Results 1 to 6 of 6

Beginner, trying to load external data between two dates specified via userform

  1. #1
    Registered User
    Join Date
    09-25-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    3

    Beginner, trying to load external data between two dates specified via userform

    Hi all, i am new to this site and have heard great things.

    i feel i might have been thrown in the deep end of visual basic and would appreciate any help or just to know weather i am in the right direction.

    I have an external database file which i created a macro to access which offers me a box to enter two dates, >= date x and <=date z. I need to replace these dates with inputted dates via input boxes on a userform which loads on excel open. Difficult?

    What ive got.

    --------------------------------------------------------------------------------------------------
    Please Login or Register  to view this content.
    I have tried replacing the two current dates with things like TBStartDates.value and TBEndDates.value??

    or heading along the lines of

    Criteria1:=">=" & Format(Me.TBStartDates.Value, "mm/dd/yy"), Operator:=xlAnd, _
    Criteria2:="<" & Format(Me.TBEndDates.Value, "mm/dd/yy")

    but i am clueless and close to giving up.

    thanks

    Rob

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Beginner, trying to load external data between two dates specified via userform

    My guess is that you will have to include the single quote as part of the literal string.

    I always use Debug.Print ConnectionString to output to the immediate window so I can see EXACTLY what is being passed.

    Debug.Print "SELECT slotapp.slotdate FROM slotapp.slotapp WHERE (slotapp.slotdate>=' & Format(Me.TBStartDates.Value, "mm/dd/yy")'" And slotapp.slotdate<=' & Format(Me.TBStartDates.Value, "mm/dd/yy")'"
    David
    (*) Reputation points appreciated.

  3. #3
    Registered User
    Join Date
    09-25-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Beginner, trying to load external data between two dates specified via userform

    Thanks David much appreciated, Still not quite there i have hit a run time error 438 meaning i haven't defined something? Which strikes me as weird being the macro worked before i added the input boxes which i believed i defined.

  4. #4
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Beginner, trying to load external data between two dates specified via userform

    Quote Originally Posted by RobertSteggles View Post
    Please Login or Register  to view this content.
    It looks like the hard-coded date format is YYYYMMDD, so try the following SQL string as the CommandText property:
    Please Login or Register  to view this content.
    Post responsibly. Search for excelforum.com

  5. #5
    Registered User
    Join Date
    09-25-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Beginner, trying to load external data between two dates specified via userform

    Thanks Chippy

    Did you mean replace the CommandText array with the SQL String? like so..

    Please Login or Register  to view this content.
    I still haven't got the dates to load correctly, a table is created in excel but just say "getting external data" but never loads. i am also coming across problems with the .Refresh BackgroundQuery:=False code can you shed any light on this?

  6. #6
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Beginner, trying to load external data between two dates specified via userform

    Quote Originally Posted by RobertSteggles View Post
    Did you mean replace the CommandText array with the SQL String?
    No, you still need to set the CommandText property because that's what ListObject uses to query the database. I meant like this, after the SQL = "...":

    .CommandText = SQL

    Or set the property directly:

    .CommandText = "Select xxxx From yyyy etc."

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1