473,587 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Quick question on setting a parameter in a query

7 New Member
Hi there,

Does anyone know how to set a parameter to be "Like 1*" returning 1000, 1100, 1200, 1210 and so on starting with a "1"? Cant seem to get the syntex

Currently my code is:

Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef

Set dbs = CurrentDb
Set qdf = dbs.QueryDefs(" ReportGeneratio n")

qdf.Parameters( 0) = Like 1* <------- this is the line I need help in
qdf.Execute


Set qdf = Nothing
Set dbs = Nothing

Any and all help appreciated.

Thanks
Ronald
Jun 12 '07 #1
5 1614
ADezii
8,834 Recognized Expert Expert
Hi there,

Does anyone know how to set a parameter to be "Like 1*" returning 1000, 1100, 1200, 1210 and so on starting with a "1"? Cant seem to get the syntex

Currently my code is:

Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef

Set dbs = CurrentDb
Set qdf = dbs.QueryDefs(" ReportGeneratio n")

qdf.Parameters( 0) = Like 1* <------- this is the line I need help in
qdf.Execute


Set qdf = Nothing
Set dbs = Nothing

Any and all help appreciated.

Thanks
Ronald
  1. In the ReportGeneratio n Query, specify the Criteria as follows:
    Expand|Select|Wrap|Line Numbers
    1. Like [Enter Number:] & "*"
  2. Change
    Expand|Select|Wrap|Line Numbers
    1. qdf.Parameters(0) = Like 1*  TO qdf.Parameters(0) = "1"
  3. It seems that you are attempting to Run a SELECT Query. If this is the case, you cannot do this via the Execute Method of a QueryDef Object.
Jun 12 '07 #2
ronaldchua
7 New Member
  1. In the ReportGeneratio n Query, specify the Criteria as follows:
    Expand|Select|Wrap|Line Numbers
    1. Like [Enter Number:] & "*"
  2. Change
    Expand|Select|Wrap|Line Numbers
    1. qdf.Parameters(0) = Like 1*  TO qdf.Parameters(0) = "1"
  3. It seems that you are attempting to Run a SELECT Query. If this is the case, you cannot do this via the Execute Method of a QueryDef Object.
Hi ADezil,

Thanks for your reply. I tried what you recommended. An input box pops up when i run the code and it says "Enter number: ". subsequently when i enter '1' everythign from that point on works fine.

But still it seems we're having trouble with the qdf.Parameters( 0) = "1" line. Any suggestions? You are right, it's a select query that I'm trying to export to Excel. If the code will make it more clear:

Thanks,
Ronald




Option Compare Database
Option Explicit

Sub ReportSFBayArea ()

Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim objXLApp As Object

Dim folderpath As String
Dim TemplateName As String
Dim Timecode As Integer
Dim Yr As Integer
Dim Qtr As Integer
Dim x As Integer
Dim y As Integer
Dim Area As Integer

Set dbs = CurrentDb
Set qdf = dbs.QueryDefs(" ReportGeneratio n")
Set objXLApp = CreateObject("E xcel.Applicatio n")


MsgBox ("This command will export the data to an Excel File for report generation. Afterwards, proceed to run the Macro 'GenerateReport ' in Excel")

qdf.Parameters( 0) = "1"

folderpath = "C:\HousingMark etReport\Report s\"
TemplateName = "Charting source codes.xls"

objXLApp.Workbo oks.Open (folderpath & TemplateName)
objXLApp.Applic ation.Visible = True
On Error Resume Next
Kill (folderpath & "Temp.xls")

objXLApp.Active Workbook.SaveAs folderpath & "Temp.xls"
objXLApp.Active Workbook.Close savechanges:=Fa lse

objXLApp.Applic ation.Quit

DoCmd.TransferS preadsheet acExport, acSpreadsheetTy peExcel9, "ReportGenerati on", "c:\HousingMark etReport\Report s\Temp.xls"

objXLApp.Applic ation.DisplayAl erts = False

objXLApp.Applic ation.Visible = True
objXLApp.Workbo oks.Open (folderpath & "Temp.xls")
objXLApp.Worksh eets("sheet1"). cells.Delete
objXLApp.Worksh eets("sheet1"). Delete

x = 1
y = 1

Do While objXLApp.cells( x, y) <> "TimeCode" And IsEmpty(objXLAp p.cells(x, y)) = False
y = y + 1
Loop

Do
x = x + 1
Loop While CInt(objXLApp.c ells(x + 1, y)) > CInt(objXLApp.c ells(x, y)) And IsEmpty(objXLAp p.cells(x + 1, y)) = False

Timecode = CInt(objXLApp.c ells(x, y))
Qtr = Timecode Mod 4
If Qtr = 0 Then Qtr = 4
Yr = (Timecode - Qtr) / 4

On Error Resume Next
Kill (folderpath & Yr & "Q" & Qtr & "Report.xls ")
objXLApp.Active Workbook.SaveAs folderpath & Yr & "Q" & Qtr & "Report.xls "
Kill (folderpath & "Temp.xls")

Set objXLApp = Nothing
Set qdf = Nothing
Set dbs = Nothing

DoCmd.Quit


End Sub
Jun 12 '07 #3
ADezii
8,834 Recognized Expert Expert
Hi ADezil,

Thanks for your reply. I tried what you recommended. An input box pops up when i run the code and it says "Enter number: ". subsequently when i enter '1' everythign from that point on works fine.

But still it seems we're having trouble with the qdf.Parameters( 0) = "1" line. Any suggestions? You are right, it's a select query that I'm trying to export to Excel. If the code will make it more clear:

Thanks,
Ronald

Option Compare Database
Option Explicit

Sub ReportSFBayArea ()

Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim objXLApp As Object

Dim folderpath As String
Dim TemplateName As String
Dim Timecode As Integer
Dim Yr As Integer
Dim Qtr As Integer
Dim x As Integer
Dim y As Integer
Dim Area As Integer

Set dbs = CurrentDb
Set qdf = dbs.QueryDefs(" ReportGeneratio n")
Set objXLApp = CreateObject("E xcel.Applicatio n")


MsgBox ("This command will export the data to an Excel File for report generation. Afterwards, proceed to run the Macro 'GenerateReport ' in Excel")

qdf.Parameters( 0) = "1"

folderpath = "C:\HousingMark etReport\Report s\"
TemplateName = "Charting source codes.xls"

objXLApp.Workbo oks.Open (folderpath & TemplateName)
objXLApp.Applic ation.Visible = True
On Error Resume Next
Kill (folderpath & "Temp.xls")

objXLApp.Active Workbook.SaveAs folderpath & "Temp.xls"
objXLApp.Active Workbook.Close savechanges:=Fa lse

objXLApp.Applic ation.Quit

DoCmd.TransferS preadsheet acExport, acSpreadsheetTy peExcel9, "ReportGenerati on", "c:\HousingMark etReport\Report s\Temp.xls"

objXLApp.Applic ation.DisplayAl erts = False

objXLApp.Applic ation.Visible = True
objXLApp.Workbo oks.Open (folderpath & "Temp.xls")
objXLApp.Worksh eets("sheet1"). cells.Delete
objXLApp.Worksh eets("sheet1"). Delete

x = 1
y = 1

Do While objXLApp.cells( x, y) <> "TimeCode" And IsEmpty(objXLAp p.cells(x, y)) = False
y = y + 1
Loop

Do
x = x + 1
Loop While CInt(objXLApp.c ells(x + 1, y)) > CInt(objXLApp.c ells(x, y)) And IsEmpty(objXLAp p.cells(x + 1, y)) = False

Timecode = CInt(objXLApp.c ells(x, y))
Qtr = Timecode Mod 4
If Qtr = 0 Then Qtr = 4
Yr = (Timecode - Qtr) / 4

On Error Resume Next
Kill (folderpath & Yr & "Q" & Qtr & "Report.xls ")
objXLApp.Active Workbook.SaveAs folderpath & Yr & "Q" & Qtr & "Report.xls "
Kill (folderpath & "Temp.xls")

Set objXLApp = Nothing
Set qdf = Nothing
Set dbs = Nothing

DoCmd.Quit


End Sub
I have a quick, down-and-dirty solution that is not very elegant, but it should definately work. Just 2 simple steps:
  1. Delete the line qdf.Parameters( 0) = "1". The fact that this is a SELECT and not an ACTION Query changes everything. Now, you cannot resolve the single Parameter in this manner and use the Execute Method of the QueryDef Object, so just remove the line.
  2. Insert this line prior to the TransferSpreads heet line of code as indicated below. We'll let SendKeys insert the 1 and ENTER Key into the Parameter Dialog Box. For a different Parameter, us a different number, but the syntax must remain the same:
    Expand|Select|Wrap|Line Numbers
    1. SendKeys "1{ENTER}"
    2. DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "ReportGeneration", "c:\HousingMarketReport\Reports\Temp.xls"
  3. Let me know how you make out.
Jun 13 '07 #4
ronaldchua
7 New Member
I have a quick, down-and-dirty solution that is not very elegant, but it should definately work. Just 2 simple steps:
  1. Delete the line qdf.Parameters( 0) = "1". The fact that this is a SELECT and not an ACTION Query changes everything. Now, you cannot resolve the single Parameter in this manner and use the Execute Method of the QueryDef Object, so just remove the line.
  2. Insert this line prior to the TransferSpreads heet line of code as indicated below. We'll let SendKeys insert the 1 and ENTER Key into the Parameter Dialog Box. For a different Parameter, us a different number, but the syntax must remain the same:
    Expand|Select|Wrap|Line Numbers
    1. SendKeys "1{ENTER}"
    2. DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "ReportGeneration", "c:\HousingMarketReport\Reports\Temp.xls"
  3. Let me know how you make out.
Hey ADezii,

Yep it works great! Thanks for your help and I learnt a new function today!

Ronald
Jun 13 '07 #5
ADezii
8,834 Recognized Expert Expert
Hey ADezii,

Yep it works great! Thanks for your help and I learnt a new function today!

Ronald
You're quite welcome.
Jun 13 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
7923
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8221
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.