473,657 Members | 2,371 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,2or 3)" 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 2928
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
2658
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 button and it runs the query into the form and nothing appears
5
2038
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 to hold patient information for research purposes. What I'm trying to do is create a form-based query system that will be easier (and less dangerous) for my future users to use to search the patient information. Let me outline the specifics,...
1
5309
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 in add or add new record form. The query will return one to 0 records so this is my option. Im guessing the form load event would be the place but not sure how to go about it.
6
3529
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). I'd like to be able to have a user click on the say, RECEIVE PAYMENT button that will open the payments form. This form should open to the loan that was selected from the LOANSELECT box. This form also has a box on it to switch to different...
1
2326
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 estimate categories however. The siginificance is, all of the estimates are in the same table, but there are different forms for viewing and editing each type. Each estimate record has a field for EstimateType. The user selects an estimate from...
10
3046
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") combo box 2 named "cbowwselect" displayed as "wk" based on qry Qry WkList (field: Year, wk) displaying only wk field. OPEN FORM (2) BUTTON (@@@)
5
1692
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 where query and the criteria is based on the values of the above listed form fields. Here is my delima: If a user types 05 into the Fiscal Week field on the form then the query runs properly; however if a 5 is typed then the query does not process...
1
1610
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 persons transactions. The ideal situation would be that the executed query would remain as part of the record because there will be many of these "searches" stored within this form. I have:
3
4519
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 variables then: FORM.RecordSource = SQL . Works fine but, if I wish to make changes is a hard work. The question is: Is here any way to pass values directly to the RecordSource query ? The same question for a ListBos RowSource.
0
1287
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 separate is because not all items will need a risk assessment. I have a form for adding items to the register which has multiple tabs the first one fill out the asset register table and has a primary key of asset id which is auto number. The second...
0
8399
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
8312
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,...
0
8827
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8606
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...
1
6169
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
5632
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
4159
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2732
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1622
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.