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?
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.
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.
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: - Public Sub showPart(ByRef sPart As String)
-
If Len(sPart) > 0 Then
-
If DCount("Part", "Table1", "Part='" & sPart & "'") > 0 Then
-
DoCmd.OpenForm "Form1", , , "Part='" & sPart & "'"
-
ElseIf DCount("Part", "Table2", "Part='" & sPart & "'") > 0 Then
-
DoCmd.OpenForm "Form2", , , "Part='" & sPart & "'"
-
ElseIf DCount("Part", "Table3", "Part='" & sPart & "'") > 0 Then
-
DoCmd.OpenForm "Form3", , , "Part='" & sPart & "'"
-
End If
-
End If
-
End Sub
Then just call the Sub: - Call showPart(Forms![Switchboard].Part)
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.
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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)....
|
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...
| |
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")
...
|
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...
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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: 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...
|
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...
| |
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...
| |