Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default changing a recorded macro - date problem....

Hi!

I recorded a macro in Excel, downloading a range of data from our SQLserver.
I now want to change the date and timestamp I entered in the macro to a value
that a user types in a cell in Excel.

This is the VBA code:
Sub Import()
'
' Import Macro
' Macro recorded 23.09.2005 by Daan'

'
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DSN=SQL04;UID=Daan;APP=Microsoft Office
2003;WSID=####;DATABASE=###;Trusted_Connection=Yes " _
, Destination:=Range("A1"))
.CommandText = Array( _
"SELECT POM_Machinedata.DATUM_AKTUELL,
POM_Machinedata.TOWEINSATZGEWICHT" & Chr(13) & "" & Chr(10) & "FROM
POM.dbo.POM_Machinedata POM_Machinedata" & Chr(13) & "" & Chr(10) & "WHERE
(POM_Machinedata.DATUM_AKTUELL={ts '2005-07-13 13:25:38'} And POM_Machined" _
, _
"ata.DATUM_AKTUELL<={ts '2005-09-22 10:59:53'})" & Chr(13) & "" &
Chr(10) & "ORDER BY POM_Machinedata.DATUM_AKTUELL" _
)
.Name = "Query from SQL04"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub



Now I want to change the date '2005-07-13 13:25:38' to a cell name, for
example to the date in cell A1 and the date '2005-09-22 10:59:53' to the date
in cell A2.

By simply replacing the date by the cell name, I run into problems in the
last line (.Refresh BackgroundQuery:=False).

Any help is welcome!

Have a nice weekend,

Daan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default changing a recorded macro - date problem....

"SELECT POM_Machinedata.DATUM_AKTUELL, POM_Machinedata.TOWEINSATZGEWICHT" &
_
Chr(13) & "" & Chr(10) & _
"FROM POM.dbo.POM_Machinedata POM_Machinedata" & _
Chr(13) & "" & Chr(10) &_
"WHERE (POM_Machinedata.DATUM_AKTUELL={ts '" & Range("A1").Text &
"'} And " & _
"POM_Machinedata.DATUM_AKTUELL<={ts '" & Range("A2").Text & "'})" &
_
Chr(13) & "" & Chr(10) & "ORDER BY POM_Machinedata.DATUM_AKTUELL" )


--
HTH

Bob Phillips

"Daan" wrote in message
...
Hi!

I recorded a macro in Excel, downloading a range of data from our

SQLserver.
I now want to change the date and timestamp I entered in the macro to a

value
that a user types in a cell in Excel.

This is the VBA code:
Sub Import()
'
' Import Macro
' Macro recorded 23.09.2005 by Daan'

'
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DSN=SQL04;UID=Daan;APP=Microsoft Office
2003;WSID=####;DATABASE=###;Trusted_Connection=Yes " _
, Destination:=Range("A1"))
.CommandText = Array( _
"SELECT POM_Machinedata.DATUM_AKTUELL,
POM_Machinedata.TOWEINSATZGEWICHT" & Chr(13) & "" & Chr(10) & "FROM
POM.dbo.POM_Machinedata POM_Machinedata" & Chr(13) & "" & Chr(10) & "WHERE
(POM_Machinedata.DATUM_AKTUELL={ts '2005-07-13 13:25:38'} And

POM_Machined" _
, _
"ata.DATUM_AKTUELL<={ts '2005-09-22 10:59:53'})" & Chr(13) & "" &
Chr(10) & "ORDER BY POM_Machinedata.DATUM_AKTUELL" _
)
.Name = "Query from SQL04"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub



Now I want to change the date '2005-07-13 13:25:38' to a cell name, for
example to the date in cell A1 and the date '2005-09-22 10:59:53' to the

date
in cell A2.

By simply replacing the date by the cell name, I run into problems in the
last line (.Refresh BackgroundQuery:=False).

Any help is welcome!

Have a nice weekend,

Daan



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default changing a recorded macro - date problem....

HI Bob,

Thanks for your quick reply.
I have changed my code, but I am still running into a runtime error `1004`
Genral ODBC error.......

Any thoughts how to solve this?

Daan

"Bob Phillips" wrote:

"SELECT POM_Machinedata.DATUM_AKTUELL, POM_Machinedata.TOWEINSATZGEWICHT" &
_
Chr(13) & "" & Chr(10) & _
"FROM POM.dbo.POM_Machinedata POM_Machinedata" & _
Chr(13) & "" & Chr(10) &_
"WHERE (POM_Machinedata.DATUM_AKTUELL={ts '" & Range("A1").Text &
"'} And " & _
"POM_Machinedata.DATUM_AKTUELL<={ts '" & Range("A2").Text & "'})" &
_
Chr(13) & "" & Chr(10) & "ORDER BY POM_Machinedata.DATUM_AKTUELL" )


--
HTH

Bob Phillips

"Daan" wrote in message
...
Hi!

I recorded a macro in Excel, downloading a range of data from our

SQLserver.
I now want to change the date and timestamp I entered in the macro to a

value
that a user types in a cell in Excel.

This is the VBA code:
Sub Import()
'
' Import Macro
' Macro recorded 23.09.2005 by Daan'

'
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DSN=SQL04;UID=Daan;APP=Microsoft Office
2003;WSID=####;DATABASE=###;Trusted_Connection=Yes " _
, Destination:=Range("A1"))
.CommandText = Array( _
"SELECT POM_Machinedata.DATUM_AKTUELL,
POM_Machinedata.TOWEINSATZGEWICHT" & Chr(13) & "" & Chr(10) & "FROM
POM.dbo.POM_Machinedata POM_Machinedata" & Chr(13) & "" & Chr(10) & "WHERE
(POM_Machinedata.DATUM_AKTUELL={ts '2005-07-13 13:25:38'} And

POM_Machined" _
, _
"ata.DATUM_AKTUELL<={ts '2005-09-22 10:59:53'})" & Chr(13) & "" &
Chr(10) & "ORDER BY POM_Machinedata.DATUM_AKTUELL" _
)
.Name = "Query from SQL04"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub



Now I want to change the date '2005-07-13 13:25:38' to a cell name, for
example to the date in cell A1 and the date '2005-09-22 10:59:53' to the

date
in cell A2.

By simply replacing the date by the cell name, I run into problems in the
last line (.Refresh BackgroundQuery:=False).

Any help is welcome!

Have a nice weekend,

Daan




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default changing a recorded macro - date problem....

What do you mean '...still...'. Were you getting that before?

You might try Format(Range("A1").Value, "yyyy-mm-dd hh:mm:ss")

instead of Range("A1").Text

etc.

--
HTH

Bob Phillips

"Daan" wrote in message
...
HI Bob,

Thanks for your quick reply.
I have changed my code, but I am still running into a runtime error `1004`
Genral ODBC error.......

Any thoughts how to solve this?

Daan

"Bob Phillips" wrote:

"SELECT POM_Machinedata.DATUM_AKTUELL,

POM_Machinedata.TOWEINSATZGEWICHT" &
_
Chr(13) & "" & Chr(10) & _
"FROM POM.dbo.POM_Machinedata POM_Machinedata" & _
Chr(13) & "" & Chr(10) &_
"WHERE (POM_Machinedata.DATUM_AKTUELL={ts '" &

Range("A1").Text &
"'} And " & _
"POM_Machinedata.DATUM_AKTUELL<={ts '" & Range("A2").Text &

"'})" &
_
Chr(13) & "" & Chr(10) & "ORDER BY

POM_Machinedata.DATUM_AKTUELL" )


--
HTH

Bob Phillips

"Daan" wrote in message
...
Hi!

I recorded a macro in Excel, downloading a range of data from our

SQLserver.
I now want to change the date and timestamp I entered in the macro to

a
value
that a user types in a cell in Excel.

This is the VBA code:
Sub Import()
'
' Import Macro
' Macro recorded 23.09.2005 by Daan'

'
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DSN=SQL04;UID=Daan;APP=Microsoft Office
2003;WSID=####;DATABASE=###;Trusted_Connection=Yes " _
, Destination:=Range("A1"))
.CommandText = Array( _
"SELECT POM_Machinedata.DATUM_AKTUELL,
POM_Machinedata.TOWEINSATZGEWICHT" & Chr(13) & "" & Chr(10) & "FROM
POM.dbo.POM_Machinedata POM_Machinedata" & Chr(13) & "" & Chr(10) &

"WHERE
(POM_Machinedata.DATUM_AKTUELL={ts '2005-07-13 13:25:38'} And

POM_Machined" _
, _
"ata.DATUM_AKTUELL<={ts '2005-09-22 10:59:53'})" & Chr(13) &

"" &
Chr(10) & "ORDER BY POM_Machinedata.DATUM_AKTUELL" _
)
.Name = "Query from SQL04"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub



Now I want to change the date '2005-07-13 13:25:38' to a cell name,

for
example to the date in cell A1 and the date '2005-09-22 10:59:53' to

the
date
in cell A2.

By simply replacing the date by the cell name, I run into problems in

the
last line (.Refresh BackgroundQuery:=False).

Any help is welcome!

Have a nice weekend,

Daan






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default changing a recorded macro - date problem....

exactly, I got it the first time, when I simply replaced the date by the
cellname. Now, with your new syntax, I still got this error.....

BTW: the last line of the VBA code is .Refresh BackgroundQuery:=False which
looks strange to me while the other lines do not have the := but the normal =
(see my first post with the VBA code).
I am not a SQL specialist at all, so I don´t have a clue what these
expressions mean..... But changing the last := into = gives me another error
messag, somthing about problems with `converting datetime into character
string´ in SQL....

Daan

"Bob Phillips" wrote:

What do you mean '...still...'. Were you getting that before?

You might try Format(Range("A1").Value, "yyyy-mm-dd hh:mm:ss")

instead of Range("A1").Text

etc.

--
HTH

Bob Phillips

"Daan" wrote in message
...
HI Bob,

Thanks for your quick reply.
I have changed my code, but I am still running into a runtime error `1004`
Genral ODBC error.......

Any thoughts how to solve this?

Daan

"Bob Phillips" wrote:

"SELECT POM_Machinedata.DATUM_AKTUELL,

POM_Machinedata.TOWEINSATZGEWICHT" &
_
Chr(13) & "" & Chr(10) & _
"FROM POM.dbo.POM_Machinedata POM_Machinedata" & _
Chr(13) & "" & Chr(10) &_
"WHERE (POM_Machinedata.DATUM_AKTUELL={ts '" &

Range("A1").Text &
"'} And " & _
"POM_Machinedata.DATUM_AKTUELL<={ts '" & Range("A2").Text &

"'})" &
_
Chr(13) & "" & Chr(10) & "ORDER BY

POM_Machinedata.DATUM_AKTUELL" )


--
HTH

Bob Phillips

"Daan" wrote in message
...
Hi!

I recorded a macro in Excel, downloading a range of data from our
SQLserver.
I now want to change the date and timestamp I entered in the macro to

a
value
that a user types in a cell in Excel.

This is the VBA code:
Sub Import()
'
' Import Macro
' Macro recorded 23.09.2005 by Daan'

'
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DSN=SQL04;UID=Daan;APP=Microsoft Office
2003;WSID=####;DATABASE=###;Trusted_Connection=Yes " _
, Destination:=Range("A1"))
.CommandText = Array( _
"SELECT POM_Machinedata.DATUM_AKTUELL,
POM_Machinedata.TOWEINSATZGEWICHT" & Chr(13) & "" & Chr(10) & "FROM
POM.dbo.POM_Machinedata POM_Machinedata" & Chr(13) & "" & Chr(10) &

"WHERE
(POM_Machinedata.DATUM_AKTUELL={ts '2005-07-13 13:25:38'} And
POM_Machined" _
, _
"ata.DATUM_AKTUELL<={ts '2005-09-22 10:59:53'})" & Chr(13) &

"" &
Chr(10) & "ORDER BY POM_Machinedata.DATUM_AKTUELL" _
)
.Name = "Query from SQL04"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub



Now I want to change the date '2005-07-13 13:25:38' to a cell name,

for
example to the date in cell A1 and the date '2005-09-22 10:59:53' to

the
date
in cell A2.

By simply replacing the date by the cell name, I run into problems in

the
last line (.Refresh BackgroundQuery:=False).

Any help is welcome!

Have a nice weekend,

Daan








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default changing a recorded macro - date problem....

Solved the problem! Made a mistake with the dd-mm-yyyy indication......

Thanks for your help and enjoy your weekend!

Cheers,
Daan

"Daan" wrote:

exactly, I got it the first time, when I simply replaced the date by the
cellname. Now, with your new syntax, I still got this error.....

BTW: the last line of the VBA code is .Refresh BackgroundQuery:=False which
looks strange to me while the other lines do not have the := but the normal =
(see my first post with the VBA code).
I am not a SQL specialist at all, so I don´t have a clue what these
expressions mean..... But changing the last := into = gives me another error
messag, somthing about problems with `converting datetime into character
string´ in SQL....

Daan

"Bob Phillips" wrote:

What do you mean '...still...'. Were you getting that before?

You might try Format(Range("A1").Value, "yyyy-mm-dd hh:mm:ss")

instead of Range("A1").Text

etc.

--
HTH

Bob Phillips

"Daan" wrote in message
...
HI Bob,

Thanks for your quick reply.
I have changed my code, but I am still running into a runtime error `1004`
Genral ODBC error.......

Any thoughts how to solve this?

Daan

"Bob Phillips" wrote:

"SELECT POM_Machinedata.DATUM_AKTUELL,

POM_Machinedata.TOWEINSATZGEWICHT" &
_
Chr(13) & "" & Chr(10) & _
"FROM POM.dbo.POM_Machinedata POM_Machinedata" & _
Chr(13) & "" & Chr(10) &_
"WHERE (POM_Machinedata.DATUM_AKTUELL={ts '" &

Range("A1").Text &
"'} And " & _
"POM_Machinedata.DATUM_AKTUELL<={ts '" & Range("A2").Text &

"'})" &
_
Chr(13) & "" & Chr(10) & "ORDER BY

POM_Machinedata.DATUM_AKTUELL" )


--
HTH

Bob Phillips

"Daan" wrote in message
...
Hi!

I recorded a macro in Excel, downloading a range of data from our
SQLserver.
I now want to change the date and timestamp I entered in the macro to

a
value
that a user types in a cell in Excel.

This is the VBA code:
Sub Import()
'
' Import Macro
' Macro recorded 23.09.2005 by Daan'

'
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DSN=SQL04;UID=Daan;APP=Microsoft Office
2003;WSID=####;DATABASE=###;Trusted_Connection=Yes " _
, Destination:=Range("A1"))
.CommandText = Array( _
"SELECT POM_Machinedata.DATUM_AKTUELL,
POM_Machinedata.TOWEINSATZGEWICHT" & Chr(13) & "" & Chr(10) & "FROM
POM.dbo.POM_Machinedata POM_Machinedata" & Chr(13) & "" & Chr(10) &

"WHERE
(POM_Machinedata.DATUM_AKTUELL={ts '2005-07-13 13:25:38'} And
POM_Machined" _
, _
"ata.DATUM_AKTUELL<={ts '2005-09-22 10:59:53'})" & Chr(13) &

"" &
Chr(10) & "ORDER BY POM_Machinedata.DATUM_AKTUELL" _
)
.Name = "Query from SQL04"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub



Now I want to change the date '2005-07-13 13:25:38' to a cell name,

for
example to the date in cell A1 and the date '2005-09-22 10:59:53' to

the
date
in cell A2.

By simply replacing the date by the cell name, I run into problems in

the
last line (.Refresh BackgroundQuery:=False).

Any help is welcome!

Have a nice weekend,

Daan






Reply
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
Unique problem with recorded macro Junior[_3_] Excel Programming 2 September 19th 05 09:51 PM
Problem with a recorded macro to create two pivot tables from same data rjamison Excel Programming 0 June 14th 05 12:14 AM
Problem with a recorded macro to create two pivot tables from same data Pete Straman via OfficeKB.com[_2_] Excel Programming 1 April 20th 05 05:28 PM
how is the syntax to replace a date, recorded within a macro with a cell value ? thomipilot[_2_] Excel Programming 0 October 1st 04 12:34 PM
how is the syntax to replace a date, recorded within a macro with a cell value ? thomipilot Excel Programming 1 September 30th 04 05:18 PM


All times are GMT +1. The time now is 02:47 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"