473,503 Members | 2,150 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to open a form based on a SQL Query pointing to tables

4 New Member
I have a database with 3 forms with 3 separate tables. All the forms are linked to their individual tables and have a Part field. So, I want to open the specific form that has this specific Part.
Easiest way I felt is to have an SQL statement that compares all the tables Part field with my Switchboard Part field. And that is where I am stuck. Once the SQL determines the table with the right Part#, how do I get it to open the Form linked and continue with my data input?

My PartQuery:
Select Distinct Table1.Part from Table1 where ((([Table1].Part)=(Forms![Switchboard].Part)));
UNION ALL
Select Distinct Table2.Part from Table2 where ((([Table2].Part)=(Forms![Switchboard].Part)));
UNION ALL
Select Distinct Table3.Part from Table3 where ((([Table3].Part)=(Forms![Switchboard].Part)));

The Query works and finds the right Part#. Now what I would like to put is a DoCmd.Openform "Form(1,2or3)" before the UNION ALL step once it finds the table with the Part#.

Is there someway to open the corresponding form once the Part# is found?
Jul 31 '15 #1
6 2923
Rabbit
12,516 Recognized Expert Moderator MVP
Is there a reason why you have them in separate tables? It's usually better design to have similar data in one table.
Jul 31 '15 #2
stimp
4 New Member
Different equipment with different setups. It's a very old database with type of equipment getting their own table and form. Over the years this equipment has gotten various part numbers.
Jul 31 '15 #3
jforbes
1,107 Recognized Expert Top Contributor
You could create a Method like the following to open the correct Form and show the Part Number:
Expand|Select|Wrap|Line Numbers
  1. Public Sub showPart(ByRef sPart As String)
  2.     If Len(sPart) > 0 Then
  3.         If DCount("Part", "Table1", "Part='" & sPart & "'") > 0 Then
  4.             DoCmd.OpenForm "Form1", , , "Part='" & sPart & "'"
  5.         ElseIf DCount("Part", "Table2", "Part='" & sPart & "'") > 0 Then
  6.             DoCmd.OpenForm "Form2", , , "Part='" & sPart & "'"
  7.         ElseIf DCount("Part", "Table3", "Part='" & sPart & "'") > 0 Then
  8.             DoCmd.OpenForm "Form3", , , "Part='" & sPart & "'"
  9.         End If
  10.     End If
  11. End Sub
Then just call the Sub:
Expand|Select|Wrap|Line Numbers
  1. Call showPart(Forms![Switchboard].Part)
Jul 31 '15 #4
stimp
4 New Member
That would go on my switchboard I presume. I've been trying to rework it from that angle, but being Friday and close to quitting time my brain just didn't want to work.

Thanks for this, I'll give it a try.
Jul 31 '15 #5
jforbes
1,107 Recognized Expert Top Contributor
You can put it in your Switchboard and it will work just fine. I typically put Methods like that in a Module, then they can be called from anywhere in the project where there is a Part Number, which can be really handy. But that is completely up to you.
Jul 31 '15 #6
stimp
4 New Member
Thanks jforbes that worked great.

I'd rather run this through VBA as I am more familiar with it than SQL. Not sure why I didn't think of this way to begin with. If we ever duplicate that part in multiple tables I will have to think of a fix. In the meantime it runs great, and this database has been going strong for almost 20 years with no duplication except accidental entries in the wrong form.
Aug 5 '15 #7

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

Similar topics

2
2643
by: cwhite | last post by:
I'm having problems with a form based query The user makes a selection from a drop box, there are only two choices: Current Former the user makes a choice and clicks the preview report...
5
2032
by: SeanCly10 | last post by:
Hi all. I don't want to sound like a complete idiot here, but I'm somewhat limited in my coding knowledge, and I need some advice and help. I'm working on a database that will eventually be used...
1
5295
by: starke1120 | last post by:
Is there a way to open a form based on query type.. Example.. If a certain query result is 1 then open the form to this result.. If the query results are NULL or 0 results, then open open for...
6
3523
by: Markus_989 | last post by:
I have a LOANS table that has a list of loan details for different borrowers. I have a main switchboard with a LOANSELECT combo box (that displays a list of borrower last names and loan numbers)....
1
2314
by: Kevin | last post by:
The menu form has two options, one to create a new estimate, the second to open an existing estimate. Under option two is a list box containing all of the estimates. There are several different...
10
3035
by: Beatrice | last post by:
I need to open a form selecting all data from a previous form i.e: Form 1) combo box 1 named "cboYearSelect" displayed as "Year" based on qry QryYearList ( only one field "Year") ...
5
1681
by: iChappy | last post by:
I have a query based off of two fields in an Access form: Fiscal Week (user manual inputs #) & Fiscal Year (combo box defaulted to current year however may select other years) The query is a...
1
1601
by: MikeMikerson | last post by:
Hello, I am need to create a subform (no problem) of a form based query (a problem). I need a form that will prompt the user to enter in a name, and the form will then display a query of the...
3
4505
by: Mihail | last post by:
I have some global variables. I use this variables to open a form based on a query with parameters. Now I use the On Load event to prepare an SQL string which include values of the global...
0
1282
by: benkelly89 | last post by:
Hi To give a bit of background this is an asset register for all assets and pat testing database in one. Two tables concerned are asset register and risk assessments. The reason the tables are...
0
7205
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
7093
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
7287
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
7349
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...
0
7467
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...
1
5022
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
4688
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...
1
746
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
399
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.