473,394 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Build Sql Statements VBA

4
I am interested in developing a search screen for users. There are a dozen or more fields which the users can select Yes, No, Unknown or leave blank. I would like to be able to build a Sql Statement from what the users have selected and refresh my query which is displayed in a subform on the same from.

The users would be able to see the matching data and then copy and paste the results it to an excel file to further interogate.

I've attached a zip file containing an example of what I am trying to achieve.

Idealy, I was hoping someone could provide me with a few points on building sql statements in vba and then using them in a query.

Any help/advice or even examples would be very much appreciated.

Kind regards,
Mike
Attached Files
File Type: zip Example.zip (18.7 KB, 76 views)
Mar 6 '10 #1
2 1863
MJC22
4
Hi,

I looked on a few other websites and was able to create a solution

For anyone interest attached is my solution. Please let me know if it could be improved as this is my first time using Sql

Mike
Attached Files
File Type: zip Example_Solution.zip (20.2 KB, 104 views)
Mar 7 '10 #2
NeoPa
32,556 Expert Mod 16PB
One of the most popular (frequently occurring rather than best liked) problems we get is with SQL strings being manipulated in VBA code.

The reason this is so difficult is that all the work is being done at a level of redirection. What I mean by this is that the coder is never working directly with the SQL itself, but rather with code which in turn, is relied on to produce the SQL that they are envisaging is required. It's rather similar to the problems coders have historically had dealing with pointers.

Anyway, a technique I often suggest to coders struggling with this (at any level. This happens to experienced coders too.) is to use either the MsgBox() function, or Debug.Print into the Immediate Pane of the debugger window, to display the value of the SQL in the string before using it (That's assuming you're not good with debugging generally. Personally I would trace to the line, then display the value prior to allowing execution of the string - See Debugging in VBA). It's really much easier to appreciate what a SQL string is meant to do, and where there may be problems, when you can see it in its entirety, and in its true form, rather than as the code is about to create it.
Mar 7 '10 #3

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

Similar topics

3
by: WC Justice | last post by:
I need to build an UPDATE statement that copies the values of roughly 40 fields from a table that stores standard or default values into a table of specific contracts. There are 8 or so fields in...
15
by: grunar | last post by:
After some thought on what I need in a Python ORM (multiple primary keys, complex joins, case statements etc.), and after having built these libraries for other un-named languages, I decided to...
6
by: Brian Henry | last post by:
I am trying to tell if my site is running as a debug build or not in asp.net 1.1 you could say #IF DEBUG DO SOMETHING HERE #ENDIF but in ASP.NET 2.0 it seems not to work anymore... why...
3
by: Eric Davies | last post by:
We've implemented a 5D box data type and have implemented both RTree and GiST access methods under PostgresSQL 7.4 and PostgresSQL 7.4.1. The 5D box internally looks like: struct Box5D{ float...
0
by: mail.surya | last post by:
This is one appicaiton that I was working on yesterday, and then it was working fine. Today I had got a new functional update to be done. I made a new private function and it was to be called from...
1
by: Egbert Nierop \(MVP for IIS\) | last post by:
Hi, I have had AtlTrace statements, but for file logging and debugging purposes, I wrote something similar. But when I release the code, the compiler does not 'ignore' the statements just as...
10
by: musosdev | last post by:
I've got a function that needs to work slightly differently on the development server from the production server, but of course I don't want to be changing code just before compiling a release...
4
by: nmrcarl | last post by:
I'm trying to upgrade a large project from VS 6.0 to VS 2005. After fixing a lot of things that changed (mostly sloppy coding in the original project that VS2005 didn't allow), I got the release...
2
by: Wayne Sepega | last post by:
We are currently having an issue with one of our web applications. Some users receive an exception when using the app, but the method that has the error in the stack trace has a few places that...
1
by: okonita | last post by:
Hi all, I have a T-SQL FUNCTION that I am trying to convert to DB2 SQL function. I ran the code through IBM migration Tool but was unable to get a clean conversion. So okay, I ran the code...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
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,...
0
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...
0
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...

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.