MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old May 23rd, 2002, 12:32 PM   #1
tealeaf
Board Regular
 
Join Date: May 2002
Location: mtl, canada
Posts: 160
Default

hi say i want to pass a string to another function ie
Call func(astr)
but astr looks like "..." & Chr(13) & "..."
so when it is passed Chr(13) is no longer part of the string.
basically i want the whole thing to act as one string called astr
tealeaf is offline   Reply With Quote
Old May 23rd, 2002, 12:39 PM   #2
tealeaf
Board Regular
 
Join Date: May 2002
Location: mtl, canada
Posts: 160
Default

maybe the code would clarify what i so incoherently am trying to ask. see COstr is a command for a query in SQL so i need the Chr(13) and the Chr(10)...

Sub theQuery()
COstr = "SELECT" & Chr(13) & "" & Chr(10) & "FROM"
Call QueryFour("D1", COstr)
End Sub

tealeaf is offline   Reply With Quote
Old May 23rd, 2002, 12:56 PM   #3
dk
MrExcel MVP
 
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
Default

Quote:
On 2002-05-23 11:39, tealeaf wrote:
maybe the code would clarify what i so incoherently am trying to ask. see COstr is a command for a query in SQL so i need the Chr(13) and the Chr(10)...

Sub theQuery()
COstr = "SELECT" & Chr(13) & "" & Chr(10) & "FROM"
Call QueryFour("D1", COstr)
End Sub

Hi,

Sorry but I don't understand what you're trying to do. Why do you need to include the carriage return character (13) in an SQL query? There's no need for that if what you're trying to do is get the SELECT and the FROM on different lines.

Can you please clarify a little further?

Regards,
Dan
dk is offline   Reply With Quote
Old May 23rd, 2002, 01:01 PM   #4
tealeaf
Board Regular
 
Join Date: May 2002
Location: mtl, canada
Posts: 160
Default

Quote:

Sorry but I don't understand what you're trying to do.
that makes 2 of us
what i'm trying to do is pass the string COstr to another function. In this function, it will be used in an SQL query. kinda looks like
.Command = COstr

the reason i'm doing this, is i will be making several queries and if i just had one function called say MyQuery(...) then I could just pass it the different strings which all resemble my COstr example in terms of format.
thanks
tealeaf is offline   Reply With Quote
Old May 23rd, 2002, 01:12 PM   #5
dk
MrExcel MVP
 
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
Default

Sorry, but I'm still confused - mainly by this:-

Quote:
so i need the Chr(13) and the Chr(10)...
Why are you using Chr(13) and Chr(10) in the first place? Is the string being displayed somewhere else first and are you using the CR and LF characters for neatness?

I think it's best if you post your code, what you would like to happen and indicate where in the code you are having the difficulty.

Dan
dk is offline   Reply With Quote
Old May 23rd, 2002, 01:23 PM   #6
tealeaf
Board Regular
 
Join Date: May 2002
Location: mtl, canada
Posts: 160
Default

my code:
this is a query that works:

' date
date1 = Format([b1] & " 07:30", "yyyy-mm-dd hh:mm:ss")
date2 = Format([b1] + 1 & " 07:30", "yyyy-mm-dd hh:mm:ss")
datemid = Format([b1] & " 19:30", "yyyy-mm-dd hh:mm")
[b2] = date1
[c2] = date2



' QUERY FOR Perte de gaz CO
COstr = "SELECT GC_CO_Generation_H.Date, GC_CO_Generation_H.No_Fr, GC_CO_Generation_H.Vent, GC_CO_Generation_H.Supply" & Chr(13) & "" & Chr(10) & "FROM Opp.dbo.GC_CO_Generation_H GC_CO_Generation_H" & Chr(13) & "" & Chr(10) & "WHERE (GC_CO_Generation_H.Date>{ts '" & date1 & "'}) AND (GC_CO_Generation_H.Date<={ts '" & date2 & "'}) AND (GC_CO_Generation_H.No_Fr<>9)"
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=OPP;Description=OPP;UID=dumaisa;PWD=opp;APP=Microsoft® Query;WSID=WQITTRACONFDDP;DATABASE=OPP;Address=172.30.2.70,1433;UseP" _
), Array("rocForPrepare=0;QuotedId=No")), Destination:=Range("AA3"))
.CommandText = COstr
.Name = "Lancer la requête à partir de OPP"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With

now this is the query i'm trying to get to work:

Sub theQuery()
COstr = "SELECT GC_CO_Generation_H.Date, GC_CO_Generation_H.No_Fr, GC_CO_Generation_H.Vent, GC_CO_Generation_H.Supply" & Chr(13) & "" & Chr(10) & "FROM Opp.dbo.GC_CO_Generation_H GC_CO_Generation_H" & Chr(13) & "" & Chr(10) & "WHERE (GC_CO_Generation_H.Date>{ts '" & date1 & "'}) AND (GC_CO_Generation_H.Date<={ts '" & date2 & "'}) AND (GC_CO_Generation_H.No_Fr<>9)"
Call QueryFour("D1", COstr)
End Sub

Sub QueryFour(mydstn As String, mystr As String)
'
' QueryFour Macro
' Macro enregistrée le 2002-05-23 par STAGIAIRE_DPF
'

'
Range("C:Z").Select
Selection.Delete
date1 = Format([b1] & " 07:30", "yyyy-mm-dd hh:mm:ss")
date2 = Format([b1] + 1 & " 07:30", "yyyy-mm-dd hh:mm:ss")
datemid = Format([b1] & " 19:30", "yyyy-mm-dd hh:mm")
[b2] = date1
[c2] = date2

' QUERY FOR Perte de gaz CO

With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=OPP;Description=OPP;UID=dumaisa;PWD=opp;APP=Microsoft® Query;WSID=WQITTRACONFDDP;DATABASE=OPP;Address=172.30.2.70,1433;UseP" _
), Array("rocForPrepare=0;QuotedId=No")), Destination:=Range(mydstn))
.CommandText = mystr
.Name = "Lancer la requête à partir de OPP"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
end sub

thanks for your help
teal
tealeaf is offline   Reply With Quote
Old May 23rd, 2002, 01:26 PM   #7
tealeaf
Board Regular
 
Join Date: May 2002
Location: mtl, canada
Posts: 160
Default

format of my previous post was confusing...sorry think this might help
Quote:
this is a query that works:

' date
date1 = Format([b1] & " 07:30", "yyyy-mm-dd hh:mm:ss")
date2 = Format([b1] + 1 & " 07:30", "yyyy-mm-dd hh:mm:ss")
datemid = Format([b1] & " 19:30", "yyyy-mm-dd hh:mm")
[b2] = date1
[c2] = date2

' QUERY FOR Perte de gaz CO
COstr = "SELECT GC_CO_Generation_H.Date, GC_CO_Generation_H.No_Fr, GC_CO_Generation_H.Vent, GC_CO_Generation_H.Supply" & Chr(13) & "" & Chr(10) & "FROM Opp.dbo.GC_CO_Generation_H GC_CO_Generation_H" & Chr(13) & "" & Chr(10) & "WHERE (GC_CO_Generation_H.Date>{ts '" & date1 & "'}) AND (GC_CO_Generation_H.Date<={ts '" & date2 & "'}) AND (GC_CO_Generation_H.No_Fr<>9)"
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=OPP;Description=OPP;UID=dumaisa;PWD=opp;APP=Microsoft® Query;WSID=WQITTRACONFDDP;DATABASE=OPP;Address=172.30.2.70,1433;UseP" _
), Array("rocForPrepare=0;QuotedId=No")), Destination:=Range("AA3"))
.CommandText = COstr
.Name = "Lancer la requête à partir de OPP"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
now this is the query i'm trying to get to work:
Quote:
Sub theQuery()
COstr = "SELECT GC_CO_Generation_H.Date, GC_CO_Generation_H.No_Fr, GC_CO_Generation_H.Vent, GC_CO_Generation_H.Supply" & Chr(13) & "" & Chr(10) & "FROM Opp.dbo.GC_CO_Generation_H GC_CO_Generation_H" & Chr(13) & "" & Chr(10) & "WHERE (GC_CO_Generation_H.Date>{ts '" & date1 & "'}) AND (GC_CO_Generation_H.Date<={ts '" & date2 & "'}) AND (GC_CO_Generation_H.No_Fr<>9)"
Call QueryFour("D1", COstr)
End Sub

Sub QueryFour(mydstn As String, mystr As String)
date1 = Format([b1] & " 07:30", "yyyy-mm-dd hh:mm:ss")
date2 = Format([b1] + 1 & " 07:30", "yyyy-mm-dd hh:mm:ss")
datemid = Format([b1] & " 19:30", "yyyy-mm-dd hh:mm")
[b2] = date1
[c2] = date2

' QUERY FOR Perte de gaz CO

With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=OPP;Description=OPP;UID=dumaisa;PWD=opp;APP=Microsoft® Query;WSID=WQITTRACONFDDP;DATABASE=OPP;Address=172.30.2.70,1433;UseP" _
), Array("rocForPrepare=0;QuotedId=No")), Destination:=Range(mydstn))
.CommandText = mystr
.Name = "Lancer la requête à partir de OPP"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
end sub
tealeaf is offline   Reply With Quote
Old May 24th, 2002, 07:24 AM   #8
tealeaf
Board Regular
 
Join Date: May 2002
Location: mtl, canada
Posts: 160
Default

give it a try Ian? heehee
tealeaf is offline   Reply With Quote
Old May 24th, 2002, 07:51 AM   #9
Ian Mac
MrExcel MVP
 
Join Date: Feb 2002
Location: Newcastle, UK
Posts: 1,174
Default

Quote:
On 2002-05-23 12:12, dk wrote:
Sorry, but I'm still confused - mainly by this:-

Quote:
so i need the Chr(13) and the Chr(10)...
Why are you using Chr(13) and Chr(10) in the first place? Is the string being displayed somewhere else first and are you using the CR and LF characters for neatness?

I think it's best if you post your code, what you would like to happen and indicate where in the code you are having the difficulty.

Dan
Why are you using these?

Also, you haven't explained why it doesn't work, that is to say, is it query that doesn't work or the code?

If it's the code where does it breakdown?

If the Query, why not, just no data? not what you asked for?

These will be helpful in answering your problem.

Regards
__________________
"Have a good time......all the time"
Ian Mac
Ian Mac is offline   Reply With Quote
Old May 24th, 2002, 08:10 AM   #10
tealeaf
Board Regular
 
Join Date: May 2002
Location: mtl, canada
Posts: 160
Default

Well the exact SQL request looks like:
SELECT GC_CO_Generation_H.Date, GC_CO_Generation_H.No_Fr, GC_CO_Generation_H.Vent, GC_CO_Generation_H.Supply
FROM Opp.dbo.GC_CO_Generation_H GC_CO_Generation_H
WHERE (GC_CO_Generation_H.Date>{ts '2002-05-09 00:00:00'}) AND (GC_CO_Generation_H.Date<{ts '2002-05-10 00:00:00'}) AND (GC_CO_Generation_H.No_Fr<>9)


i modified the dates to be variables.
the code in VBA of the same retrieval looks like:

Application.WindowState = xlMinimized
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=OPP;Description=OPP;UID=dumaisa;PWD=opp;APP=Microsoft® Query;WSID=WQITTRACONFDDP;DATABASE=OPP;Address=172.30.2.70,1433;UseP" _
), Array("rocForPrepare=0;QuotedId=No")), Destination:=Range("A4"))
.CommandText = Array( _
"SELECT GC_CO_Generation_H.Date, GC_CO_Generation_H.No_Fr, GC_CO_Generation_H.Supply, GC_CO_Generation_H.Vent" & Chr(13) & "" & Chr(10) & "FROM Opp.dbo.GC_CO_Generation_H GC_CO_Generation_H" & Chr(13) & "" & Chr(10) & "WHERE (GC_CO_Generation_H.Date>{ts '20" _
, _
"02-05-09 07:30:00'}) AND (GC_CO_Generation_H.Date<={ts '2002-05-10 07:30:00'}) AND (GC_CO_Generation_H.No_Fr<>9)" _
)
.Name = "Lancer la requête à partir de OPP"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub


I made the .Command = COstr
and COstr = "..."
The problem with my trying to pass the string, is i guess it's not coming out in the right format so it's not doing the retrieval properly and gives me an error in the last line of the VBA code.
better?
tealeaf is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 06:11 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes