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: 989
Default Data Import from External Database


Not being a VBA whizz i recorded a macro which imports data from an external
database and when i run this macro it works great

One of the fields on this database is a date field and i want this query to
only bring in the records based on a date the user would enter in an input box

I've tried using input box and a variable which would hold the date and
refer to this variable in the line
"WHERE (GL_EXTRACT.RECEIVED_DATE={ts '2009-06-10 00:00:00'})" _
)

the problem i'm having is the date is in double quotes which would make the
variable no good.

is it possible to change this code so that the user can enter a date and the
query would bring back records based on that date?

Sub Macro2()
'
' Macro2 Macro
' Macro recorded 24/06/2009 by User
'

'
With ActiveSheet.QueryTables.Add(Connection:=Array(Arra y( _

"ODBC;DSN=BETN;UID=MRBLOGGS;;DBQ=BETN;DBA=W;APA=T; EXC=F;FEN=T;QTO=F;FRC=10;FDL=10;LOB=T;RST=T;BTD=F; BAM=IfAllSuccessful;NUM=NLS;DPM=F;" _
), Array("MTS=T;MDI=F;CSR=F;FWC=F;FBS=64000;TLO=O;")) ,
Destination:=Range("A1" _
))
.CommandText = Array( _
"SELECT GL_EXTRACT.EXTRACTN, GL_EXTRACT.RECEIVED_DATE,
GL_EXTRACT.RECORD_COUNT, GL_EXTRACT.ACCOUNT_TYPE, GL_EXTRACT.ACCOUNTN,
GL_EXTRACT.BUS_CLASS, GL_EXTRACT.FUND_CLASS, GL_EXTRACT.CO_CODE, GL_EXTRACT" _
, _
".ORACLE_AC, GL_EXTRACT.INTERFUND, GL_EXTRACT.DAYS_CREDITS,
GL_EXTRACT.DAYS_DEBITS" & Chr(13) & "" & Chr(10) & "FROM UNIWIN.GL_EXTRACT
GL_EXTRACT" & Chr(13) & "" & Chr(10) & "WHERE (GL_EXTRACT.RECEIVED_DATE={ts
'2009-06-10 00:00:00'})" _
)
.Name = "Query from BETN"
.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

 
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
Import external data New database quearry Dhimant Excel Programming 3 December 14th 08 12:07 PM
Tool bar: Data/Import external data/New database query Daniel Setting up and Configuration of Excel 3 February 28th 08 08:40 AM
database query not showing foxpro database How I import data mangat New Users to Excel 1 June 24th 07 03:31 PM
Import External Data: Saving changes to the database Jean Excel Discussion (Misc queries) 1 April 8th 07 11:12 PM
PLEASE!! How can I un-grey the 'Data-Import External Data-Import Data' option ??? kirkm[_6_] Excel Programming 13 August 8th 06 10:01 AM


All times are GMT +1. The time now is 08:44 AM.

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"