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: 36
Default Problem in SQL Query

Hi everyone

I am trying to retrieve the data from MS Access database through ODBC query through a function given below

Sub query_gen(fproject_master, fproject_master1, fproject_master2, fmptable,
fmptable1, fpdetail, fpdetail1, fpdetail2, fpdetail3, fpdetail4, query1, query2,
query3, query4, query5, fcycle_type

direc = Worksheets("QUERY_BUILDER").Range("BH1").Valu
datab = Worksheets("QUERY_BUILDER").Range("BH2").Valu

' Sheet2.Columns("A:BA").NumberFormat = "General


With ActiveSheet.QueryTables.Add(Connection:=Array(Arra y(
"ODBC;DSN=MS Access Database;DBQ=" + CStr(datab) +
";DefaultDir=\\phome5\common\AT\AT-Amendments;DriverId=25;"),
Array("FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;")), Destination:=
Range("A7")


.Sql = Array("SELECT " & fproject_master & " " & fproject_master1 & " "
& fproject_master2 & " " & fmptable & " " & fmptable1 & " " & fpdetail & " "
& fpdetail1 & " " & fpdetail2 & " " & fpdetail3 & " "
& fpdetail4 & " " & fcycle_type & " FROM `" & CStr(datab) &
"`.M_P_Table M_P_Table, `" + CStr(datab) &
"`.Cycle_Type Cycle_Type, `" & CStr(datab) + "`.P_Detail P_Detail, `"
+ CStr(datab) + "`.Project_Master Project_Master"
& " WHERE M_P_Table.M_P_No = P_Detail.M_P_No AND M_P_Table.Project_No = "
& "Project_Master.Project_No AND Cycle_Type.cycle_project=P_Detail.Serial_No"
& "AND ((" & query1 & query2 & query3 & query4 & query5 & "))"

FieldNames = Tru
.RefreshStyle = xlInsertDeleteCell
.RowNumbers = Fals
.FillAdjacentFormulas = Fals
.RefreshOnFileOpen = Fals
.HasAutoFormat = Tru
.BackgroundQuery = Tru
.TablesOnlyFromHTML = Tru
.Refresh BackgroundQuery:=Fals
.SavePassword = Tru
.SaveData = False 'Will not save the dat
End Wit
End Su

Whenever I am trying to run this query
it is giving 2 errors
First it gives error on line : Sheet2.Columns("A:BA").NumberFormat = "General
the error is
Run-Time Error "1004" :unable to set the NumberFormat property of Range Class

So I commented this line

and the second error its giving type mismatch on line

..Sql = Array("SELECT " & fproject_master & " " & fproject_master1 & " "
& fproject_master2 & " " & fmptable & " " & fmptable1 & " " & fpdetail & " "
& fpdetail1 & " " & fpdetail2 & " " & fpdetail3 & " "
& fpdetail4 & " " & fcycle_type & " FROM `" & CStr(datab) &
"`.M_P_Table M_P_Table, `" + CStr(datab) &
"`.Cycle_Type Cycle_Type, `" & CStr(datab) + "`.P_Detail P_Detail, `"
+ CStr(datab) + "`.Project_Master Project_Master"
& " WHERE M_P_Table.M_P_No = P_Detail.M_P_No AND M_P_Table.Project_No = "
& "Project_Master.Project_No AND Cycle_Type.cycle_project=P_Detail.Serial_No"
& "AND ((" & query1 & query2 & query3 & query4 & query5 & "))"

It was not giving this error earlier. Its all of a sudden. What could be the possible reason of this sudden appearance of error

TI
Shilp

 
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
Problem with Web Query Albert Excel Discussion (Misc queries) 0 August 19th 09 05:23 AM
Query Problem Freshman Excel Worksheet Functions 0 September 26th 06 09:57 AM
Problem with MS Query - can't edit query jarems Excel Discussion (Misc queries) 2 December 12th 05 09:42 AM
Query problem Will Excel Discussion (Misc queries) 2 November 21st 05 03:02 PM
Problem with .Background Query option of ODBC Query Shilps Excel Programming 0 April 19th 04 06:41 AM


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