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

Access 2003 - opening a form to show specific record

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 the form
"Sparesform" to open when I double click on the "index" field for the
record I wish to view. The index field is part of a subform. What is
happening at the moment is the form "Sparesform" is opening but does
not go to the correct record but instead goes to, what appears to be a
new record. My where condition of the code appears to be assigning the
correct index number to "forms![sparesform]![number]" but this does not
seem to be carried out when the sparesform is opened.

Index is a numeric data type (ie its an auto number)
Can you shine some light on my problem.
Hereis my code:

Private Sub index_DblClick(Cancel As Integer)

Dim stDocName As String, stLinkCriteria As String

stDocName = "Sparesform"
stLinkCriteria = "forms![sparesform]![Number] = " & Me![index]

DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms![sparesform]![Condition].SetFocus

End Sub

Please help

Martin R

Jul 5 '06 #1
3 9164
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In the Sparesform's Open event (or the Load event) you have to set the
Filter or the RecordSource to the index number you have passed in the
OpenArgs parameter of the OpenForm method. E.g.:

Private Sub Form_Open(Cancel As Integer)

If Not IsNull(Me.OpenArgs) Then
Me.Filter = "Index = " & Me.OpenArgs
Me.FilterOn = True
Else
MsgBox "No Index Passed", vbCritical
Cancel = True
End If

End Sub

--
MGFoster:::mgf00 <atearthlink <decimal-pointnet
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRKwaLYechKqOuFEgEQL0vwCcD4KcZtS1OGsAbNNhoKcLaL 17L10AnjlE
zJgWQbdJ9pzjz+iUBxCvS+Ez
=0nqk
-----END PGP SIGNATURE-----
MartinR wrote:
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 the form
"Sparesform" to open when I double click on the "index" field for the
record I wish to view. The index field is part of a subform. What is
happening at the moment is the form "Sparesform" is opening but does
not go to the correct record but instead goes to, what appears to be a
new record. My where condition of the code appears to be assigning the
correct index number to "forms![sparesform]![number]" but this does not
seem to be carried out when the sparesform is opened.

Index is a numeric data type (ie its an auto number)
Can you shine some light on my problem.
Hereis my code:

Private Sub index_DblClick(Cancel As Integer)

Dim stDocName As String, stLinkCriteria As String

stDocName = "Sparesform"
stLinkCriteria = "forms![sparesform]![Number] = " & Me![index]

DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms![sparesform]![Condition].SetFocus

End Sub
Jul 5 '06 #2
"MartinR" wrote
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 the form
"Sparesform" to open when I double click on the "index" field for the
record I wish to view. The index field is part of a subform. What is
happening at the moment is the form "Sparesform" is opening but does
not go to the correct record but instead goes to, what appears to be a
new record. My where condition of the code appears to be assigning the
correct index number to "forms![sparesform]![number]" but this does not
seem to be carried out when the sparesform is opened.

Index is a numeric data type (ie its an auto number)
Can you shine some light on my problem.
Hereis my code:

Private Sub index_DblClick(Cancel As Integer)

Dim stDocName As String, stLinkCriteria As String

stDocName = "Sparesform"
stLinkCriteria = "forms![sparesform]![Number] = " & Me![index]

DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms![sparesform]![Condition].SetFocus

End Sub
Your stLinkCriteria is in error... you appear to be trying to set a Control
on "sparesform" to the value of the Index, but you need to set a criteria
for the pertinent Field in the underlying RecordSource of that Form. If the
Field is named "Number", then it should read:

stLinkCriteria = "[Number] = " & Me![index]

If the Field and the TextBox Control in which it is displayed have the same
name, you may need to rename the TextBox something like txtNumber to prevent
confusion. The WhereCondition only provides a Filter for the SQL or Query or
Table that is the RecordSource of a Form... you can't use it to set a value
into a Control.

And, as a matter of fact, the Forms Collection only includes _open_ forms,
so I think you should be getting an error on that DoCmd.OpenForm. And, by
the way, you should not need to SetFocus, just make sure that Condition is
the first Control in the Tab Order (with the Form open in Design View), on
the menu, View | Tab Order and follow the dialog box.

Larry Linson
Microsoft Access MVP
Jul 5 '06 #3
I'm sorry but i couldn't follow what i was suppose to do. I put your
code into the database but it didn't seem to have any effect. is there
an easier way of writing code that opens a form and displays the same
record that i clicked on in the sub form?

Jul 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Brian Andrus | last post by:
Ok. I upgraded to MS Access 2003 recently and now I am having great heartache. In Access 2002, when I opened a table to view the data, there were wonderful little "plus" signs that I could click...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
4
by: pmhaupt2 | last post by:
I developed an Access 2003 program that will allow the user to produce a group of Word letters that merge with data records from an Access database. I created a mail merge Word document and...
52
by: Neil | last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server at the same time. We're moving to SQL Server...
7
by: needin4mation | last post by:
Hi, I have an Access 2002 - 2003 database. I am using Access 2003. Whenever I link an image all it shows is the filename. Not the image. Other versions of Access can link the image just fine. ...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
4
by: zufie | last post by:
I have a main form containing a command SEND button that prompts an email form to pop up. The email address(es) that are supposed to appear on the email form are those corresponding to the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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:
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
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...
0
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 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.