Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to use DTPicker value in VBA code 1

Status
Not open for further replies.

pcsmurf

IS-IT--Management
Apr 26, 2002
47
GB
On my form I have a DTPicker control. I also have a command button which when picked should use the value of the DTPicker control in a query.

The code of the command button is:

Dim db As Database, rst As Recordset, qdf As QueryDef
Dim sSQL As String
Dim cOutFilename, cPriceDate As String

Set db = CurrentDb()
Set qdf = db.CreateQueryDef("")

cPriceDate = Format(dtCurrent.Value, "mm/dd/yy")

cOutFilename = "D_" & cPriceDate

sSQL = "SELECT rsDataStreamA.ComGrp, rsDataStreamA.SubGrp, rsDataStreamA.RawCom, rsDataStreamA.ComType, rsDataStreamA.Description, rsDataStreamA.PrintDescrip1, rsDataStreamA.PrintDescrip2, rsPrices.ContractNo, rsPrices.Contract, rsPrices.AsAt, rsPrices.SettSpot, rsPrices.Prev, rsPrices.High, rsPrices.Low "
sSQL = sSQL & "INTO " & cOutFilename & " "
sSQL = sSQL & "FROM rsDataStreamA INNER JOIN rsPrices ON rsDataStreamA.ComID = rsPrices.ComID "
sSQL = sSQL & "WHERE (((rsPrices.AsAt) = #" & cPriceDate & "#)) "
sSQL = sSQL & "ORDER BY rsDataStreamA.tblCommodityGroups.Ord, rsDataStreamA.tblSubGroups.Ord, rsDataStreamA.tblRawCommodities.Ord, rsDataStreamA.qry_commodities.Ord;"

qdf.SQL = sSQL
qdf.Execute

This should result in a new table called D_ followed by the date of the DTPicker. However trying to run it I get

run time error '3067'
Query Input must contain at least one table or query.

Changing the line
cOutFilename = "D_" & cPriceDate
to
cOutFilename = "D_270203"

works fine. So it seems the value of cOutFilename is not being set as a string.

Any suggestions ?
 
The only difference is value of cOutFilename, with full code is D_27/02/03, explicit value is D_270203. Slash can be reserved word (and is in explioer), so building string without it can remove error.
 
pcsmurf,
try
[tt]cOutFilename = "D_" & Format(dtCurrent.Value, "mmddyy")[/tt]

combo
 
Yes, I've done that and everything now works as expected.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top