LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA/SQL date variable problem

Hello,


I want to write some code which


a) looks at a list of dates in Excel then determines the date of the
next day
b) uses the result of a) to refresh some queries
c) performs calculations on the result of b) and returns data to a
specified sheet


I have no problem with a) and c) I am struggling with the SQL part of
b).


When I run the code I get an Runtime error 13 - type mismatch, so I
guess the format of the variable is not correct. I have tried declaring



Nextdate (my variable) as a string and a date with a format type of
that given when I use a macro recording to generate the code.


Here is the macro generated SQL which runs:
With Selection.QueryTable
Criteria & "WHERE (MI_STATISTIC.ST_DATE={ts '2005-08-13 00:00:" _
, _
"00'}) AND More Criteria
.Refresh BackgroundQuery:=False
End With


Here is what I have edited it to with VB dim and Format statements
which doesn't run:
Dim Nextdate As Date
Dim Nonblank As Long


Sheets("Graphs").Select
Nonblank = Application.WorksheetFunction.**CountA(Range("c:c" ))
Cells(Nonblank, 3).Select
ActiveCell.Copy
ActiveCell(2, 1).Select
ActiveSheet.Paste
Nextdate = ActiveCell.Value
Nextdate = Format(Nextdate, "yyyy-mm-dd hh:mm:ss")
Sheets("HH Recircs").Select
Range("D4").Select
With Selection.QueryTable
Criteria & "WHERE (MI_STATISTIC.ST_DATE={ts '"" & Nextdate""'})



AND More Criteria
.Refresh BackgroundQuery:=False
End With


Can anyone point me in the right direction?


Thanks


Will

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
calc constant date from variable date & return with ability to rn. SusieQ'sQuest Excel Worksheet Functions 1 November 9th 04 08:51 PM
Compare Date in Cell VS a Variable Date to Hide Row JimI Excel Programming 3 October 10th 04 04:26 PM
Variable problem TC[_6_] Excel Programming 3 September 16th 04 09:39 PM
vba variable problem joao Excel Programming 3 December 15th 03 04:31 PM
Problem trying to us a range variable as an array variable TBA[_2_] Excel Programming 4 September 27th 03 02:56 PM


All times are GMT +1. The time now is 01:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"