I'm using Access 2007 on Windows Vista and am having some problems trying to configure a simple button. There are two tables called Clients and Contacts which are linked on clients.id and contacts.client_id. There are two forms associated with each table and I am trying to create a button to navigate from the Clients form to the Contacts form (which is a split form) but only to display the contacts where the current clients.id = contacts.client_id (eventually I would like the entry in the top of the form to be the contact with the earliest letter in the alphabet as their surname).
I turned on the Control Wizard and created the button specifying Form Operations ->Open form ->Contacts->Open the form and find specific data to display. At this stage there are no fields listed under the Clients table so I can't use the <-> button to link the fields. I have therefore tried to set up an On Click events procedure using DoCmd.OpenForm. I am not a programmer so have tried copying code from the Help and from forums such as this. My current code reads as follows (although I have tried many variations):
Private Sub Display_Contacts_for_Client_Click()
DoCmd.OpenForm "contacts", , , _
"id = forms![contacts]![client_id]"
End Sub
Upon clicking the button the Contacts form is opened but with no records displaying. Other variations on the syntax either result in run time errors, or the Contacts form being opened with all of the records displaying at the bottom of the screen.
Any help much appreciated. I have set the properties for the MSACCESS.exe to run the program as administrator as I've read that this should be set for Access 2007.
Thanks, Emma
6 8728
Hi. You will need to refer to the value of the field client_id, not its name, within the Where string. If the client_id field is a number use the first version below, and if a string use the second version: - "id = " & forms![contacts]![client_id]
or - "id = '" & forms![contacts]![client_id] & "'"
Welcome to Bytes!
-Stewart
Hi Stewart, thanks for your welcome & your help...I'm tearing my hair out with this - a seemingly straightforward database configuration project is fast turning into a time consuming, frustrating nightmare!
The client id field is numeric so I tried your first example of code but when I click on the button I get run time error 2450 and a message saying the Contacts form can't be found - I promise you it does exist!
Any further suggestions gratefully received!
Ah, I should have spotted this earlier - you appear to be trying to open form Contacts with a WHERE clause based on a control value on the same form!! That simply cannot work, and indeed explains the error message you last received, as the control concerned cannot be referenced until AFTER the form is opened - which OpenForm cannot do because of the reference to the form's ClientID control which is not yet available (until the form is open). Do you see the circular reference?
I presume you have a client ID field somewhere on the form from which you are trying to open form Contacts. If you do, you can refer to that instead, substituting the actual name of your client ID control in the expression below: - "[ID] = " & me![your client ID control name]
-Stewart
Ah, I see what you mean. I was presuming that because I had created a relationship between the two tables (linked on clients.id and contacts.client_id) that the condition would work. I have now added an invisible field for contacts.client_id to the Clients form and amended the code to read:
DoCmd.OpenForm! "Contacts", , , " ID = " & Me![Client_id]
When I click on the button now it does open the Contacts form but it is blank.
Maybe I am going about this in totally the wrong way!
Thanks for your patience.
Emma
It appears to me that you are thinking of the relationship the wrong way round. If you are trying to open the Contacts form then it is the ID field underlying the Contacts table that you need to include in the WHERE clause, and the Clients ID field value that you need to supply to it to match from one to the other. This is the reverse of what you appear to be doing.
If I can try to clarify, the idea is that you - OPEN the contact form WHERE
-
the primary key field from the contact form's recordsource table
-
is equal in value to
-
the primary key field from the client form's recordsource table
This is more likely to be something like - DoCmd.OpenForm "Contacts" ,,, "[Client_ID] = " & Me![ID]
if I am correctly understanding which key is which...
-Stewart
Stewart - you have saved the day! Thank you so much, I really appreciate your help & patience. Now I'll have a go at configuring a button to do the reverse from the Contacts form back to Clients.
Emma
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Iain Miller |
last post by:
Now this shouldn't be hard but I've been struggling on the best way as to
how to do this one for a day or 3 so I thought I'd ask the assembled
company.....
I'm writing an application that tracks...
|
by: DataBard007 |
last post by:
My Access 97 database has a form that contains text boxes that display
people's names, addresses, phone numbers, etc. The record source is a
single table.
I created a NextRecord and Previous...
|
by: Lyn |
last post by:
Hi,
I am working on a genealogy form. The only table (so far) lists everybody
in the family, one record per person. Each record has an autonum ID.
The parent form (frmMainForm) displays the...
|
by: keith |
last post by:
This may seem simple, but I'm having a bit of trouble figuring out
exactly how to do it. I'm accessing a database through an ODBC link,
and I have a query that returns only jobs completed that day...
|
by: Susan Bricker |
last post by:
Greetings. As a relative newcomer to Access, I am having trouble
deciding on how to design the form flow for updating and creating
related records. I'm looking for a variety of suggestions so...
|
by: Kevin |
last post by:
A couple of easy questions here hopefully. I've been working on two
different database projects which make use of multiple
forms.
1. Where's the best/recommended placement for command buttons...
|
by: emc_cos |
last post by:
I have a very nice parent child relationship happening between a main
form and 8 subforms.
The main form is the data entry point for a table that holds textual
data like names, notes and the...
|
by: Tony |
last post by:
I'm working on project that plays movies using Windows Media Player and
I'm controlling everything with JavaScript. Per the client I only need
to support IE 6 or greater which happens to make...
|
by: tech.rawsteak |
last post by:
I have a function that retrieves a user's login name from their
workstation and looks it up on an employee table to return their full
name (ie: jsmith -John Smith). Their full name is then...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
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...
|
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...
|
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: 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,...
| | |