473,396 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Opening different linked forms depending on criteria in first form

5
I have a list of contacts containing fields [ContactID] and [ContactType].

I need to attach code to a button which will open either "frmCustomers" or "frmSuppliers" depending on the value in [ContactType] but also to display only the record relevant to [ContactID].

Hope that makes sense.
May 1 '07 #1
7 1650
Rabbit
12,516 Expert Mod 8TB
What have you tried so far?
May 1 '07 #2
Maboo
5
I have only been able to open one form or the other to the relative record. That bit is easy. I need to be able to open one form if it is a customer and the other form if it is a supplier as they display different tabs.

I guess it will need an If Then statement but don't know where to start.

This is what I have attempted to do (try not to laugh!)

Expand|Select|Wrap|Line Numbers
  1. If Me.ContactType.Value = "Customer" Then
  2.  
  3.  
  4.     DoCmd.OpenForm "frmCustomers TabControl"
  5.  
  6.     stLinkCriteria = "[ContactID]=" & Me![ContactID]
  7.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  8.  
  9.         Else
  10.   If Me.ContactType.Value = "Supplier" Then
  11.  
  12.  
  13.     DoCmd.OpenForm "frmSuppliers TabControl"
  14.  
  15.     stLinkCriteria = "[ContactID]=" & Me![ContactID]
  16.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  17.  
  18.     End If
May 1 '07 #3
Rabbit
12,516 Expert Mod 8TB
I have only been able to open one form or the other to the relative record. That bit is easy. I need to be able to open one form if it is a customer and the other form if it is a supplier as they display different tabs.

I guess it will need an If Then statement but don't know where to start.

This is what I have attempted to do (try not to laugh!)

Expand|Select|Wrap|Line Numbers
  1. If Me.ContactType.Value = "Customer" Then
  2.  
  3.  
  4.     DoCmd.OpenForm "frmCustomers TabControl"
  5.  
  6.     stLinkCriteria = "[ContactID]=" & Me![ContactID]
  7.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  8.  
  9.         Else
  10.   If Me.ContactType.Value = "Supplier" Then
  11.  
  12.  
  13.     DoCmd.OpenForm "frmSuppliers TabControl"
  14.  
  15.     stLinkCriteria = "[ContactID]=" & Me![ContactID]
  16.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  17.  
  18.     End If
This is close. Some changes need to be made though.

1) You didn't Dim stDocName or stLinkCriteria.

2) You use two DoCmd.OpenForms to open what I assume is the same form.

3) You have stDocName as the form to open but you never populate it.

4) It's Else If on one line, not two lines.

Fix these issues and then we can tackle whatever comes up after.
May 1 '07 #4
Maboo
5
Thanks Rabbit

I've made the following changes which seem to work OK:

Expand|Select|Wrap|Line Numbers
  1. If Me.ContactType.Value = "Supplier" Then
  2.  
  3.     Dim stDocName As String
  4.     Dim stLinkCriteria As String
  5.  
  6.     DoCmd.OpenForm "frmSuppliers TabControl"
  7.  
  8.     stLinkCriteria = "[ContactID]=" & Me![ContactID]
  9.  
  10. ElseIf Me.ContactType.Value = "Customer" Then
  11.  
  12.     DoCmd.OpenForm "frmCustomers TabControl"
  13.  
  14.     stLinkCriteria = "[ContactID]=" & Me![ContactID]
  15.  
  16.     End If
Much obliged.
May 1 '07 #5
Maboo
5
No it doesn't! It opens the correct form but not to the correct record.

More help on this would be appreciated. Not very good with code.
May 1 '07 #6
Maboo
5
No it doesn't! It opens the correct form but not to the correct record.

More help on this would be appreciated. Not very good with code.
I think I've got it!

Here's what I've done:

Dim stDocName As String
Dim stLinkCriteria As String

If Me.ContactType.Value = "Customer" Then

stDocName = "frmCustomers TabControl"

ElseIf Me.ContactType.Value = "Supplier" Then

stDocName = "frmSuppliers TabControl"

End If

stLinkCriteria = "[ContactID]=" & Me![ContactID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Thanks
May 1 '07 #7
Rabbit
12,516 Expert Mod 8TB
Thanks Rabbit

I've made the following changes which seem to work OK:

Expand|Select|Wrap|Line Numbers
  1. If Me.ContactType.Value = "Supplier" Then
  2.  
  3.     Dim stDocName As String
  4.     Dim stLinkCriteria As String
  5.  
  6.     DoCmd.OpenForm "frmSuppliers TabControl"
  7.  
  8.     stLinkCriteria = "[ContactID]=" & Me![ContactID]
  9.  
  10. ElseIf Me.ContactType.Value = "Customer" Then
  11.  
  12.     DoCmd.OpenForm "frmCustomers TabControl"
  13.  
  14.     stLinkCriteria = "[ContactID]=" & Me![ContactID]
  15.  
  16.     End If
Much obliged.
1) You want to dim the variables outside the If/Then structure.

2) You want to set the value of stDocName and stLinkCriteria before you use it.

3) You want to Open the Form after you fill in the stDocName and stLinkCriteria.

4) You'll want to use both stDocName and stLinkCriteria to open the form before like you did in your first version of the code.

5) stDocName should be set to the name of your form.
May 1 '07 #8

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

Similar topics

1
by: N. Graves | last post by:
Hi, I want to have a Search Dialog box that has several text box and fields to build a search and display the results in a form. I can do everything that I need to if I us a report but I would...
2
by: neptune | last post by:
I have a query where each customer has an or . Sometimes both fields for a customer are populated, but if is null, then will be populated and vice versa. I have a form, , where I select a...
10
by: Marizel | last post by:
I'm not sure there's an easy solution to this, but thought I'd ask. I often find myself with a query which I'd like to reuse, but with a different datasource. These datasources generally have...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
3
by: MartinR | last post by:
Hi, I'm still new to writing code in vba as I've only been introduced to access three weeks ago. I have written this code below and it executes but does not do what I want it to do. What I want is...
1
by: CanuckChuck | last post by:
Hello, This question may sound too general and confusing but I am trying to keep it simple. I have a form that managers log into to view a list of the employees reporting to them. They are...
0
by: ChadK | last post by:
I am trying to open a report based on what the user selects on a form. Each individual criteria works but when I try to combine to pass multiple criteria it doesn't. I have read what I can find on...
12
by: Studiotyphoon | last post by:
Hi, I have report which I need to print 3 times, but would like to have the following headings Customer Copy - Print 1 Accounts Copy - Print 2 File Copy -Print 3 I created a macro to...
2
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
I am (still) relatively new to Windows applications, most of my experience has been Web based, and I am confused about what exactly happens when the Main() method is called and how to manipulate...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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
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,...

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.