473,387 Members | 1,534 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,387 software developers and data experts.

clicking a record in one form to open the same record in another form

40
Hello.

I have a summary form that displays a list of records. I need to know how to, by clicking a field one record, it automatically opens (redirects me to) another form (to view its details) but calling up the same record, without necessarily opening the second form then using the Find feature to call it up on the second form.

Kindly assist.

Thank you.
May 6 '15 #1
12 5094
NeoPa
32,556 Expert Mod 16PB
Open the second form using DoCmd.OpenForm() and use the WhereCondition parameter.
May 6 '15 #2
Shem K
40
Thanks, NeoPa.

I'm kinda new to VB coding, and have only recently started to including VB (thanks to some valuable input from Bytes.com! :) ) into the Access Database I'm working on. Please take me through the coding for the
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm()
and how to use the WhereCondition parameter to tackle my query.
May 6 '15 #3
NeoPa
32,556 Expert Mod 16PB
I suppose there are a number of steps.
  1. Before anything else decide if Click or DoubleClick is what you want for your trigger mechanism. The code is very similar but just clicking may happen more than you expect.
  2. Take each control on the form where you want to enable this feature and look at the Properties panel (Alt-Enter opens them for you).
  3. Find the property On Dbl Click and double-click on the name of it. This puts the string value "[Event Procedure]" in the property.
  4. Next click on the little button next to that with an ellipsis (...) on it. This takes you to the code.
  5. The code window will show you the basis of a module which should look something like :
    Expand|Select|Wrap|Line Numbers
    1. Option Compare Database
    2. Option Explicit
    3.  
    4. Private Sub txtID_DblClick()
    5.  
    6. End Sub
    Line #2 is especially important.
  6. This is the basis of your first subroutine and will vary depending on the actual names of your objects. I've assumed the control is called txtID and that it's the primary index of the table. I will further assume that the name of the form to open is frmDetail.
  7. Now, add the following code but change all bits that relate to named objects to suit your project.
    Expand|Select|Wrap|Line Numbers
    1. Option Compare Database
    2. Option Explicit
    3.  
    4. Private Sub txtID_DblClick()
    5.     Dim strWhere As String
    6.  
    7.     strWhere = Replace("([ID]=%I)", "%I", Me.txtID)
    8.     Call DoCmd.OpenForm(FormName:="frmDetail", WhereCondition:=strWhere)
    9. End Sub
Notice that line #7 specifies which records are allowed. We want only the matching record so we form a filter that handles that. I've assumed the ID is a numeric value but if it is a string then change it to :
Expand|Select|Wrap|Line Numbers
  1.     strWhere = Replace("([ID]='%I')", "%I", Me.txtID)
Notice the quotes.

Line #8 opens the form. The FormName and WhereCondition parameters seem fairly self-explanatory.

Let us know how you get on with this.
May 7 '15 #4
Shem K
40
I've tried this, but it returned the following error on execution:

----
Procedure declaration does not match description of event or procedure having the same name.
*The expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure]
*There may have been an error evaluating the function, event or macro.
----
(in this case, Event Procedure)

Please help me understand this error.


Also, the database I'm developing is intended to store records in the thousands (1.5k - 2k or more), being client Files for the company. I'm trying to create a system that calls up the original record in a second form, onClick or onDoubleClick of same record on the first form. While the filter system in the code could work for a particular record, is there a way to call out other records individually as well?


Also, is there a way to do the same using macros? And how do I go about it (will help me determine which option is easier)?
May 7 '15 #5
Shem K
40
Sorry. I forgot to mention, I'm using Access 2007
May 7 '15 #6
Shem K
40
The link below provided an executable method for my query (also contains a download for the programmer's accde. trial version).

http://ms-access-tips.blogspot.com/2...n-form-at.html

I tried using the code in my primary key field (File Ref) like this:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub File_Ref_DblClick(Cancel As Integer)
  4. On Error GoTo myError
  5. Dim varWhereClause As String
  6. varWhereClause = "File_Ref" & Me!File_Ref
  7. DoCmd.OpenForm "Paul__Matters_in_Detail", , , varWhereClause
  8. leave:
  9. Exit Sub
  10. myError:
  11. MsgBox Error$
  12. Resume Next
  13. End Sub
  14.  
And the following error message returns:
Microsoft Office Access can't find the field 'File_Ref' referred to in your expression. This is the closest I could get to solving my query so far. But alas!. What could be the issue with my coding?
May 7 '15 #7
Shem K
40
Hi all.
I finally did manage to make this possible, through the embedded macro way. I had to wrap my finger around what NeoPa suggested, and the directions on this site:
https://www.youtube.com/watch?v=RILqSTAAQpM

At the Where Condition Action Argument of Action Open Form, I inserted the below text:

Expand|Select|Wrap|Line Numbers
  1. ="[File Ref]=" & "'" & [File Ref] & "'"
This helped me solve my query.

Thanks, NeoPa, for pointing me in that direction (i.e., the Where Condition).

Regards,

Attached Images
File Type: jpg Screenshot 2015-05-08 07.38.04 (2).jpg (86.1 KB, 1477 views)
May 8 '15 #8
NeoPa
32,556 Expert Mod 16PB
Shem:
...
(in this case, Event Procedure)

Please help me understand this error.
This indicates that the name of the procedure doesn't match the name of the object associated with it. You should avoid such a problem if you follow my earlier instructions on how to create it.
Shem:
Also, is there a way to do the same using macros? And how do I go about it (will help me determine which option is easier)?
Yes. There is.

However, most experienced developers wouldn't be cruel enough to send you on that journey. They are limited in their availability and, if you progress any further in Access you will certainly get to a point where they can't do what you need. At that point you have to start again in frustration. They are also much harder to manage and maintain from my understanding.
Shem:
Microsoft Office Access can't find the field 'File_Ref' referred to in your expression. This is the closest I could get to solving my query so far. But alas!. What could be the issue with my coding?
I very strongly advise not trying to cobble together solutions from more than one place at a time. It's like trying to ride two horses. Uncomfortable as long as they are both travelling in exactly the same direction. Otherwise they'll split you apart. Not much fun for the horses either. Personally, if you choose to use me as your horse I'll be happy to help you progress your code.
Shem:
Expand|Select|Wrap|Line Numbers
  1. ="[File Ref]=" & "'" & [File Ref] & "'"
If ever you see code in that format, where the single-quotes are included as separate strings on their own, be cautious. Ask yourself if the person using such code has ever properly understood what they're doing. Other things, like calling a string variable var..., cause me to be very cautious about the code you have been working with. People will expect such a variable to be of type Variant from the var part of the name.

I'm pleased if you have something working. Every step is good when you're making progress. Nevertheless, be aware that some steps simply teach you what to avoid in future.

PS. I've just reread this and I'm concerned you may feel deflated by my comments. Don't be. You are starting out and have find solutions as and where you can. That is a good sign in itself. My advice is intended to guide rather than chastise. Be confident. It seems to me you've done well so far.
May 8 '15 #9
Shem K
40
Thanks, NeoPa. I hope I pick up the pace in VBA coding, then probably be able to accomplish much more from where I've started from.
May 14 '15 #10
Shem K
40
Hi guys.
Just an addition: I did a follow-through on the DoCmd.OpenForm on this one and recently (this morning) converted the macro events of a few forms from a copy of my project into VBA. In Access 2007, the code line for the Where Condition looks like this:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "Paul: Matters in Detail", acNormal, "", "[File Ref]=" & "'" & [File Ref] & "'", , acNormal
Hope this is useful for anyone building code on it :-).
Jun 10 '15 #11
NeoPa
32,556 Expert Mod 16PB
Thanks for the update.

BTW Do you realise there is never any good reason for concatenating two literal strings together except when together they are too long to be seen easily. "[File Ref]=" & "'" is equivalent to "[File Ref]='" and a much better (correction - worse) way to code it.

Better because it's so much easier to understand a single item than having to calculate the result of two items concatenated. TBF the task of calculating the result is simple enough, but it's very rare that such a situation is the only thing the poor maintainer has to consider while going through your code. Far better to do it the simpler and easier way (It even involves less typing).
Jun 11 '15 #12
Shem K
40
This makes a lot of sense. I'm updating my code with this one. Thanks NeoPa.
Jun 11 '15 #13

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

Similar topics

1
by: Richard | last post by:
Thats a mouthfull of a title what I'm after should be really simple. I have a form with a subform which itself has a subform the final subform contains an individuals record. The individuals...
1
by: adamj | last post by:
Hi people... Is it possible to, by using any means...use a button to open up a form on a particular record? If so how?
4
by: Rich | last post by:
Hello, I have a child form in an Mdi Parent form. I have 5 menu buttons on the Parent that I use to show the child form. Originally, in the Parent form on load event I had this line of code ...
1
by: reidarT | last post by:
How can I open a form from another form with textfields containing data from the first form. Like openargs in Access reidarT
0
by: colleen1980 | last post by:
Macro and button all works fine. It goes to other database and open the form from their. Now only problem is that there are two forms link to each other. When i click on the button it works fine...
11
by: banderson | last post by:
Hello, I know I've seen an answer to this question before, but I cannot seem to find it again. After searching for a few hours, I've decided to re-post in hopes someone can give advice and/or send...
25
by: Bigdaddrock | last post by:
I have a form which contains both customer mail and billing addresses. In some cases the billing address is the same for several customers (ex their company is picking up the bill). I must create...
0
by: Jason C | last post by:
I've got a simple database in Access 2007 with a form interface. One of the forms contains subforms and uses multiple tables, currently navigation works fine. There's also several complex queries...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
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
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,...

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.