473,499 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access 2003, Union query...or Not

4 New Member
I have two UNRELATED tables...Customers and Vehicles...

I need to make a query for when an existing customer (in customers table) needs a loaner car for a vehicle in our inventory (in vehicles table) There is no relationship between the customer or vehicle, so how can I apply this.

I tried the following:

select vehicle.[VIN]
from vehicle
where (((Vehicle.[VIN,C,30]) Like "*" & [Search for] & "*"))
UNION
select customer.[lastn]
where (((Customer.[lastn]) Like "*" & [Enter Customers Last Name] & "*"));

The first "where" prompts the user to enter a partial VIN and successfully returns the correct vehicle when run alone.
The second "where" prompts for which customer to use by entering a partial last name, which returns a single customer when run alone.

I will eventually need their name, address, DL#, which all fields are in the Customer table and understand I need the same number of tables and they must be the same type, to which they are. I just used a few fields to see what I am doing wrong.

So, when I run this, it would show the VIN only...I need to see the customers last name also - this is where I'm lost.

Over all I need one query for a form to list the vehicle info and customer info, which is in the DB, but not related.
Dec 21 '16 #1
7 1170
jforbes
1,107 Recognized Expert Top Contributor
You've done a good job at figuring out what you want to display, but I wouldn't rely on a single query to give you those results. You could get this to work, but it will be clunky and with just a bit off effort you could have an elegant solution.

What I would do...
Create a Datasheet Style Form for your Vehicle Table
Create a Datasheet Style Form for your Customers Table
Create a Single Form with Two unbound fields at the Top:
  1. txtVIN
  2. txtCustomer
Then add both of the recently created Datasheet Style Forms as SubForms, right on top of each other.

The fun part starts by adding code to both AfterUpdate events of txtVIN and txtCustomer. The code should create a string for the Filter clause and apply the Filter to the respective Datasheet SubForm. i.e. When your user enters in a VIN, the txtVin_AfterUpdate will fire, creating a where clause, and apply it to the Vehicle SubForm:
Expand|Select|Wrap|Line Numbers
  1. Dim sSQL as String
  2. sSQL = "VIN LIKE '*' & Me.txtVin.Value & '*'"
  3. Me.subVehicle.Form.Filter = sSQL 
  4. Me.subVehicle.Form.FilterOn = True
  5. Me.subVehicle.Visible = True
  6. Me.subCustomer.Visible = False
Lastly, show just the subForm related to the data that was searched.

The End result will be a Form where the user picks what they are looking for, by entering in either the VIN or Customer Name. If they enter a VIN, only Vehicle information will be displayed, if they enter a Customer Name, only the Customer information will be displayed.
Dec 21 '16 #2
Dubblosephen
4 New Member
I apologize for not relaying why I need this, the info would overlay a scanned form in a report for a loaner vehicle. Both the customer info and vehicle info would always need to be displayed. By the description, specifically the "OR", I don't think this would work.

I literally just thought of having two reports in one, or a subreport....can I have two queries in one report with a subreport? Hopefully this won't open a wormhole...?

Main or report 1 - select customer_stuff from customers;
subreport or report 2 - select VIN from vehicles;

I'm going to try this now, unless you are saying your recommendation will always return both the vehicle and customer and I just misunderstood.
Dec 21 '16 #3
PhilOfWalton
1,430 Recognized Expert Top Contributor
I believe you want a join table similar to this:-
Expand|Select|Wrap|Line Numbers
  1. TblJoinVehicleCustomer
  2. VehicleID         Long    Joint Primary Key
  3. CustomerID        Long    Joint Primary Key
  4. DateLoaned        Date
  5. DateReturned      Date
  6.  
Set appropriate relationships, and you have a record of who borrowed each vehicle and when and correspondingly who each vehicle was loaned to.

Phil
Dec 21 '16 #4
Dubblosephen
4 New Member
I cannot join. This is an existing application that I am linking to the tables via Access. Besides, no join should exist as this is vehicles in inventory that a customer may be temporarily assigned as a loaner. I never know in advance which vehicle a customer would be assigned.

There is no way to have two tables where I can select a record from table 1 (Vehicle) and a record from table 2 (Customer) and have the appropriate fields and link to the report...I can't imagine this hasn't been requested before.

Long story short, we (I) created a significant number of reports for us including State forms that auto fill using overlays to a scanned form. We literally print and sign deals, no handwriting. changes we requested from the vendor typically are not 100% of our request or use a really poor 10pt terminal font. So not professional looking. Making the reports/forms ourselves we have the flexibility to make them as professionally looking as we want.

With that said, it's not something I can request from the vendor, at least for free anyways. They typically only do things if its for the greater good, not so much a change for one customer, understandably.

((Thinking out loud...))
I will try to do something using make table which can append to a record, first for the vehicle, then the customer. Since its two-ish times a week, I can create the make table, assign record id numbers as the join and then delete the record after its printed. Since we have a signed copy, I do not need historical records. It will always be a 1 to 1 join with 1 record in each table.
Dec 23 '16 #5
jforbes
1,107 Recognized Expert Top Contributor
Is this for a Form or a Report? Your first post is about a Form, you subsequent posts seem to be about Reports. There are different approaches depending on which target you are going against.
Dec 24 '16 #6
Dubblosephen
4 New Member
I was mistaken, this definitely needs to be a report, not form. At a minimum needs to prompt for a customer and VIN since there is no relationship.
Dec 27 '16 #7
jforbes
1,107 Recognized Expert Top Contributor
If you don't want to build a Table like Phil's TblJoinVehicleCustomer to link your records together for reporting, then I would create a Form that Launches your Report. The Report Launcher Form would prompt for both the CustomerID and VehicleID and when both are supplied, it would enable the Button that launches the Report. On the Report, I would put two different SubReports, one for the Customer, the other for the Vehicle. The Source for each SubForm would be a Query that refers back to the Launcher Forms CustomerID and VehicleID.

I would not attempt a Union or Join into one Query as that will just complicate things and make maintenance more difficult.
Dec 29 '16 #8

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

Similar topics

0
3937
by: s_gregory | last post by:
The mdb is considerable size 70 +- mb. A complex union query was working well, but when an additional union select... was added into the query, selecting identical fields from a different source,...
3
6156
by: DFS | last post by:
I've been working around this for years (I believe), so I figured someone here might know: Why won't a crosstab query accept a value from a form reference? TRANSFORM...
1
1858
by: SAKTHIVEL | last post by:
Hi, Im developing applications using Visual Basic and MS-Access 2003. Union query solves my specific problems. But I unable to call this query from visual basic form like other queries. The query...
1
8365
by: dohminator | last post by:
Hello Experts, I have two systems written in Access 2003 that I'm in the process of merging. A user will be given a specific screen depending on his user name. I have a form (let's call it...
4
2479
by: rdsandy | last post by:
Hi, I have some code below in VBA for Access 2003 which is on a button called "RentalCrosstabPercTtlQtyMonthLoc_Click". This is a crosstab query which brings up rental items down the side, who...
1
2156
by: Jorgo | last post by:
In Access 2003 under Windows XP I have made a database for the local Legacy group and they require reports on Widows of various ages. I have their age calculated and shown in form view, however...
14
3625
by: bknabl | last post by:
I'm very new to creating union queries. I understand the purpose but not how to properly implement it for my purpose. So far I've created to perfectly fine crosstab queries. One shows input on a date...
7
2150
by: Zak Cowen | last post by:
I am trying to get an update query to change the password when run. At the moment I have the two fields; - Password - Change_password I want the query to update my table when the user had...
1
2063
by: Hom2013 | last post by:
HI, I'm having trouble with my SQL code truncating memo fields in my union query. Here is the code: SELECT Projects. AS Expr1 , Input2012 AS 2012Input , AS Famt , . AS Lamt ,...
0
7009
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...
0
7178
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
7390
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...
0
5475
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,...
1
4919
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...
0
3103
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...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
302
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...

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.