Hello,
I am trying to use this form:
to select a program type and generate a random list to audit. This part is working correctly. But I would like to use a variable either a number or a percent to input as the TOP x PERCENT|NUMBER in my SQL statement from the form.
My code looks like this: -
strTableName = "tblAuditSample_" & Format(Date, "ddmmmyyyy")
-
-
strSQL = "SELECT TOP 10 PERCENT tblTemp.SHC_No, tblTemp.Project_Name, tblTemp.Program_Type, tblTemp.PMC " & _
-
"INTO " & strTableName & " " & _
-
"FROM tblTemp " & _
-
"ORDER BY tblTemp.RandomNumber;"
-
-
DoCmd.SetWarnings False
-
DoCmd.RunSQL strSQL
-
DoCmd.SetWarnings True
-
When I change the hard coding to either a number or percent this works, but I want other people who are unfamiliar with VBA to be able to generate an audit report too.
Any help would be greatly appreciated!
Thanks.
4 1364 zmbd 5,501
Recognized Expert Moderator Expert
morganaj:
1) Your image link is blocked by most company IT policies in the USA and more than likely else where in the world. If the file is small enough, use the advanced editor and then manage attchments to upload the file here.
2) if I understand correctly you want to change this: strSQL = "SELECT TOP 10 PERCENT tblTemp.SHC_No,
to this: strSQL = "SELECT TOP X PERCENT tblTemp.SHC_No,
Now because I can't see your form all I can do is provide a basic change. I must assume that there is some sort of command button that executes the VBA Script:
If the form has a text box control named "txtPercent " then you need to validate that the user entry is numeric, positive, and between 1 and 100... that code I leave to you.
Once the validation is done then: strSQL = "SELECT TOP " & me.txtPercent & " PERCENT tblTemp.SHC_No,
When I try to change the SELECT statement to include the variable, that you suggested. - strSQL = "SELECT TOP" & Me.strPercent & "PERCENT tblTemp.SHC_No, tblTemp.Project_Name, tblTemp.Program_Type, tblTemp.PMC " &
-
"INTO " & strTableName & " " & _
-
"FROM tblTemp " & _
-
"ORDER BY tblTemp.RandomNumber;"
It all turns red and gives me a "Compile error: Expected: Expression."
And if I try to run it as is I get a "Compile error: Syntax Error."
Is this because I am running Access 2007, or am I missing an object library...
Hey zmbd, thanks for the help. I figured it out. - "SELECT TOP" & " " & Me.strPercent & " " & " PERCENT
Apparently the syntax wanted a literal space to make it run properly.
Thanks for the help!
zmbd 5,501
Recognized Expert Moderator Expert
Yes, the spacing is very importaint to the SQL engine.
If you will take a very carefull look at the final string in post#2, you may notice this... if one is not expecting to look for the space it is VERY easy to overlook and is one of the more common errors fixed (next the quote marks around strings) in ACC-SQL strings.
BOL W/ Your Project.
-z
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: icrash2 |
last post by:
Hi,
I'm using PHP to submit form input to MySQL and need a way to
capitalize the first character for certain fields. Does anyone know of
some way to achieve this?
Much appreciated
|
by: Reply Via Newsgroup |
last post by:
Folks,
I am using Apache 1.3.x with PHP 4.3.x and MySQL v4.
Short question:
Before I put my web form available on the internet, how can I test it
from mis-use in such that special characters are ignored? I have tried
entering data such as `/bin/date > /tmp/1234` and this does not create a
temporary file (which is what I would expect, meaning that my form is safe).
|
by: champ.supernova |
last post by:
Hi,
I have a form which has a few different submit links, all of type
image. This is critcal to the operation of the form, as it relies on
the image co-ords being passed to another page, the processing of which
is handled by someone else.
What I need to do though, is to have a text link which simulates one of
these image inputs being clicked, as some kind on onclick event.
However, I've hit a brick wall looking for example code of how...
|
by: Nathan |
last post by:
I have an aspx page with a data grid, some textboxes, and an update button.
This page also has one html input element with type=file (not inside the data
grid and runat=server).
The update button will verify the information that has been entered and
updates the data base if the data is correct. Update will throw an exception
if the data is not validate based on some given rules. I also have a custom
error handling page to show the...
|
by: Rob Mitchell |
last post by:
(Sorry if this appears twice)
Hi,
I know this has probably been beaten to death but
I was working with Class by Stickman --
http://www.the-stickman.com which uses DOM to
create multiple file input elements in a form.
I'm trying to just hide all the form input elements
| |
by: neelay1 |
last post by:
Hi all,
I have a Javascript variable that contains the name of a form input-
input_name = "document.myform.ip"
How can I get the value of this form input, "ip" using the variable
input_name?
input_name.value returns undefined value and input_name + ".value"
returns the string document.myform.ip.value
Any help will be highly appreciated.
Thanks,
|
by: jchris |
last post by:
Hi I'm a newbie in ASP
I have a form that everytime after some processing work all its input will disappear. May I know is there any solution that i can keep da form input?
i'd tried using response.control = private and
response.buffer = true but it didn't work out though
thanks
|
by: Phil Latio |
last post by:
I've been creating an application over the last few weeks and generally
pleased with what I have produced but one area is irritating me, form
validation.
At the moment the forms are simply static html templates and the form input
is checked using a validation class. Basically each form field is checked,
every error is stored to an array and at the end of checking of the complete
form, the array is output neatly at the top of the form.
...
|
by: KeredDrahcir |
last post by:
I have a form and I'm using CSS3 to use the form input type "email". This seems to make sense since any browser that doesn't support it would default to text which is what I would otherwise use, however it does help with browsers that do support it. Firefox will check it's valid before the form can submit and iPhones will provide the E-mail keypad which I always find helpful.
I was storing an E-mail address and tried to change it but it...
|
by: Stiofan |
last post by:
Hi,
This may be a bit of a noob question.
I am writing a page which has a list of offers each with a checkbox input and 'id' set.
Later in the page a form is used to capture visitors name and email address.
I was thinking of using hidden input fields in the form, but am having difficulty transferring the values. Im thinking I'll have to go javascript, but am not as comfortable with it as I am with PHP.
If anyone has a better idea,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |