473,657 Members | 2,845 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

user to add two fields of his choice to the query

2 New Member
Greetings,

I am merging a series of different tables into one query to export decision-making information. I have some architecture issues I need to ask for help on. I have no programming training.

I will explain my structure before asking my questions.

I have data from a table (updated monthly by adding the most current month’s data) that is evaluated by certain arithmetic, given an adjective to describe it, and then being exported to the user via e-mail.

The goal is for the user to input dateperiods such that they are “JAN07” or “FEB07”, following a syntax of <3 letter abbreviation for month>(last two digits in year).

Currently, there are RECORDS with data like:

Record Name PART NUMBER JAN07 FEB07 MAR07
RECORD1 abc 123 155 132
RECORD2 def 235 254 244
RECORD3 fgh 323 355 389

(there’s other fields of data, but it is not involved in any of the calculations as always tied to the PART NUMBER)

Record Name is dependent on the part number’s characteristic. For example, if part number abc and fgh, is painted with RED, then RECORD1 and RECORD3 may have the same (RED)

PART NUMBER will never be duplicated. It is unique.

JAN07, FEB07, and MAR07 is tied to the Record Name. If RECORD 1 and RECORD 3 were the same, then the JAN07, FEB07, and MAR07 values would be identical.

The Record Name comes from a table that stores all the RecordNames and JAN07, FEB07, MAR07 fields. The PART NUMBER comes from a USER IMPORTED file.

It is easy for me to calculate (FEB07 – JAN07) / JAN07 in a query, but that is if it is defined by the user in the query itself.

I want to use a switchboard that allows the user to say, “I want to see the % change from MAR07 and JAN07” or “I want to see the change from MAR07 and FEB07”.

I’ve tried to do the [] in the field name box of a query, but it requires me to add a table. When I do that and run the query, it brings up a popup box, and then I put in JAN07 and it runs the query results, which for that expression column is simply JAN07 for every record.

How do I set It up such that my user can decide via switchboard / macro / popup box what 2 dates they want to calculate % change for?

I see 2 issues:

#1. A way for the user to add two fields of his choice to the query (JAN07, FEB07, MAR07)

#2. A way to change my expression field that does the growth calculation based on the fields chosen by #1

Thank you for your time.
I was rather pressed for time but here is the logic and partial code solution. If you have any further questions, feel free to ask. But first!
  1. Create 2 Combo Boxes on a Form (cboFirstDate and cboSecondDate).
  2. Set the RowSourceType of both Combo Boxes to Value List.
  3. Set the RowSource of both Combo Boxes to "JAN07";"FEB07" ;"MAR07";..."DE C07"
  4. You will be selecting your MMMYY Ranges from these Combos and building an SQL String from which you will create a Query.
  5. The code assumes your Table Name is tblYourTable, but replace it with the appropriate Name.
  6. The code below will create and execute a User Defined Query based on your selections in the Combo Boxes.
  7. This should definately point you in the right direction.
  8. As previously stated, if you are still stuck, either myself or one of the other Moderators/Experts will assist you. Good luck.
Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
  2. Dim MySQL As String, qryDef As QueryDef
  3.  
  4. 'Make sure both Combo Boxes have entries in them
  5. If Not IsNull(Me![cboFirstDate]) And Not IsNull(Me![cboSecondDate]) Then
  6.   'Make sure both Combo Boxes are not equal
  7.   If Me![cboFirstDate] = Me![cboSecondDate] Then
  8.     MsgBox "1st and 2nd Date selections cannot be equal", vbExclamation, "Invalid Entries"
  9.       Exit Sub
  10.   Else
  11.     'If you get here, you are good to go! DELETE existing Query if present
  12.     CurrentDb.QueryDefs.Delete "qryYourQuery"
  13.  
  14.     'Build SQL from the 2 combinations of MMMYY
  15.     MySQL = "SELECT [" & Me!cboFirstDate & "], [" & Me!cboSecondDate & "] FROM tblYourTable;"
  16.  
  17.     'Create the Query, Refresh the DB Window, then execute it
  18.     Set qryDef = CurrentDb.CreateQueryDef("qryYourQuery", MySQL)
  19.  
  20.     Application.RefreshDatabaseWindow
  21.  
  22.     DoCmd.OpenQuery "qryYourQuery"
  23.  
  24.   End If
  25. End If
  26.  
  27. Set qryDef = Nothing
Apr 19 '07 #1
1 1866
nico5038
3,080 Recognized Expert Specialist
You made it a daunting task :-)
With the present unnormalized approach I woudl just construct the query dynamically like:

dim qd as DAO.querydef

set qd = currentdb.query defs("qryDynami c")
qd.SQL = "SELECT ID, (" & me!combo2 & " - " & me!combo1 & ") / " & me!combo1 " as Percentage from tblX"

' here the query is constructed and can be used e.g. in a docmd.transfers preadsheet command to get an excel sheet that can be mailed.

Getting the idea ?

Nic;o)
Apr 23 '07 #2

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

Similar topics

2
7594
by: Bennett Haselton | last post by:
I'm looking for a PHP tutorial that specializes in how to build sites that are based around user logins. i.e. the user logs in on the front page, and are taken to a main login page where fields on the page are populated with values from some server-side database. Ideally, there would be a server-side "user" database table, with fields such as "age", so that you could insert a short tag in the PHP source like: Your age is: <?php ?> ...
5
10865
by: Megan | last post by:
Hi everybody- I'm helping a friend with a music database. She has an old one and is creating a new one. She wants to compare records and fields in the old database with records and fields in the new database. For instance, her old database has a table with Band Info in it. Her new database also has a table with Band Info in it but slightly different. I was wondering if there was an easy way to compare the fields from similar tables in...
41
3416
by: Mountain Bikn' Guy | last post by:
What is the current preferred way to save user preferences in dotnet? Is the registry the right place to do this? Can anyone recommend a good article (or book) for this topic? Thanks.
9
2900
by: Jimbo | last post by:
Hello, I have a user request to build a form in an Access database where the user can check off specific fields to pull in a query. For example, let's say I have 10 fields in a table. The user wants to be able to check off anywhere between 1 and all 10 fields in a form and have it return a select query with just the fields that were checked off. There are multiple users, so not all users will be checking off the same fields. Some...
32
2670
by: wexx | last post by:
I have been looking for some time now (reading books off Safari, searching through forums,etc) I have found no solution to this problem. I turn to anyone of you that may be able to help me. I'm trying to create a database for work, using Microsoft Access 2003 on Windows XP. I have a product licensing database and it has one table named serial numbers, that table holds all the information associated with SNs, including customer name,...
482
27568
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if this is more of a coldfusion problem or a javscript problem. So if i asked my question in the wrong section let me know an all move it to the correct place. what i am trying to display previously entered multiple fields. I am able to get my serial fields to display correctly, but i can not display my parts fields correctly. Currently this is what it does serial information 1 parts 1
82
10008
by: happyse27 | last post by:
Hi All, I modified the user registration script, but not sure how to make it check for each variable in terms of preventing junk registration and invalid characters? Two codes below : a) html b) perl script (print and inserting into database) Cheers... Andrew
9
4239
by: happyse27 | last post by:
Hi All, In perl script(item b below) where we check if html registration form are filled in properly without blank with the necessary fields, how to prompt users that the field are incomplete or blank and then go back to main page(item a below user registration html page) always, something like goggle or msn login page function... Thanks and Best Rgds, Andrew a) script called from user registration html...
45
27693
by: dizzydangler | last post by:
Hi, I'm new to access (2007, running on XP), but I've gotten some great help from this site on my project so far. However, the more I know, the more complex the problems seem to become.... I'm working with all of my data in a single table and, right now, I've got a form linked to a query that allows the user to input whatever search criteria they want through a variety of controls. I've also created a series of check boxes on the form...
0
8384
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8302
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,...
1
8499
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8601
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7314
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
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...
0
5630
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1601
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.