473,796 Members | 2,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Button points to a record in form

16 New Member
I have a MS Access database with multiple forms for data entery. All the data are stored in one table, but I have multiple forms to organize the data entry. I also have a main form that shows the record and has buttons linked to other forms for data entry. Clicking on each button will take you the form to enter the data.
So, here is what I have:
Main form with some minor information about a record (ID, name) and all the buttons, and then FORM 1, FORM 2 and so on and navigation keys. when you click on FORM2 button on thte main form it will open the FORM2 and shows the fields for the first record. The script for the button is as follows:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command20_Click()
  2. DoCmd.OpenForm "02 - Origin"
  3. End Sub
But what I really need is that when I open the main form and I go to record 30 using the navigation butons, by clicking on the FORM2 button, it opens form 2 and navigates to the same record on that form so I enter the data for that record.

How should I change the script to be able to navigate to the record corresponding to the one I have on my main form?
Dec 21 '07 #1
3 1662
patjones
931 Recognized Expert Contributor
I have a MS Access database with multiple forms for data entery. All the data are stored in one table, but I have multiple forms to organize the data entry. I also have a main form that shows the record and has buttons linked to other forms for data entry. Clicking on each button will take you the form to enter the data.
So, here is what I have:
Main form with some minor information about a record (ID, name) and all the buttons, and then FORM 1, FORM 2 and so on and navigation keys. when you click on FORM2 button on thte main form it will open the FORM2 and shows the fields for the first record. The script for the button is as follows:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command20_Click()
  2. DoCmd.OpenForm "02 - Origin"
  3. End Sub
But what I really need is that when I open the main form and I go to record 30 using the navigation butons, by clicking on the FORM2 button, it opens form 2 and navigates to the same record on that form so I enter the data for that record.

How should I change the script to be able to navigate to the record corresponding to the one I have on my main form?
Suppose that, on your main form, "ID" is stored in a text box called txtID. One way to do this is use the OpenArgs property of the OpenForm command to pass the ID of the current record to the second form:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "02- Origin", acNormal, , , , , , Me.txtID
Then, in the module for the second form, you could do something like

Expand|Select|Wrap|Line Numbers
  1.  Private Sub Form_Open(Cancel As Integer) 
  2.  
  3. Dim rst As Recordset
  4.  
  5. Set rst = Me.RecordsetClone
  6.  
  7. rst.FindFirst "[tblName].[fldID] Like ' * " & Me.OpenArgs & " * ' "
  8.  
  9. If rst.NoMatch = False Then
  10.      Me.Bookmark = rst.Bookmark
  11. End If
  12.  
  13. rst.Close
  14. Set rst = Nothing
  15.  
  16. End Sub
  17.  
In this, you would put tblName = your table's name, and fldID = the name of the field that ID is stored in.

This method assumes that:

1) ID uniquely identifies your records (otherwise FindFirst will just go to
the first record that has ID in it, even if there are many other records
that contain ID).

2) The second form is already bound to the table (e.g.
Me.RecordSource = "tblName").

Another (possibly simpler) method would be to use a SQL statement to assign a data source to the form (e.g. Me.RecordSource = "SELECT [field names] FROM [table name] WHERE [fldID] = Me.OpenArgs"). This would also be done inside the second form's VB module.

Hope this helps.

Pat
Dec 21 '07 #2
jaxjagfan
254 Recognized Expert Contributor
If you are only using one table as the data source. Have you considered using tab control? It would be just one form with multiple tabs for data entry. Users could easily navigate from tab to tab. The different tabs would always be part of the same record. I did this for an application where I had about 50 fields for display and entry. I don't like my endusers to have to scroll up and down if possible within a form.
Dec 21 '07 #3
patjones
931 Recognized Expert Contributor
If you are only using one table as the data source. Have you considered using tab control? It would be just one form with multiple tabs for data entry. Users could easily navigate from tab to tab. The different tabs would always be part of the same record. I did this for an application where I had about 50 fields for display and entry. I don't like my endusers to have to scroll up and down if possible within a form.
That's a good idea also. I've actually done it that way before with multiple tables; as long as the form's RecordSource is set properly (e.g. via a well written SQL statement), it works great.
Dec 21 '07 #4

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

Similar topics

1
3552
by: Robert Neville | last post by:
I am having some trouble with some old code revolving around custom form navigation buttons. My main form has a sub-form with these custom navigation buttons. In other words, the code should be modular and work across forms and sub-forms. My previous code was taken from the Access Expert Solutions 97 (Leszynski) many years ago. As my database became more complex with multiple sub-forms and intricate combo boxes, the code faltered. Some...
1
7320
by: John Michael | last post by:
Is it possible to detect when someone has pushed their Esc button on a form. When a form is open and someone is adding a record, if they push the esc button, the whole form gets reset to an empty record. Is it possible to detect or can you disable this so that the record does not clear? I know there is an On Dirty event for forms, but are there any events that will tell me if the form has changed from dirty to clean?
3
6225
by: Randy | last post by:
I have been able to set up a Find Record Button on my switchboard to take me to a form with the correct case number by using a parameter query and macro. When I try to run the Find Record button from the macro on the form I want to find the record in it just sits there and does not run. Could someone tell me how to fix this? Please be specific as I am new to Access.
1
1632
by: Randall Parker | last post by:
Currently in an asp:DataGrid I have a column for bringing up an edit form on a particular row and that is done by a hyperlink as follows: <asp:TemplateColumn HeaderText="Edit Record"> <ItemTemplate> <asp:HyperLink id="hyperlink1" NavigateUrl='<%# "EquipmentEdit.aspx?serial=" + DataBinder.Eval(Container, "DataItem.owner_serial_num") %>' Text='Edit' runat="server"/>
14
4973
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 for things like delete, save, edit, cancel buttons - in the footer, or on the form detail section? 2. If in the footer, how do you add them to the tab order?
1
2254
by: Bill_W_Stephens | last post by:
I need a form with two buttons and ability to detect which button was pressed. I got this code to work using a javascript global variable, but I know there must be a better way using DOM. Any suggestions? <html> <head> <script language="JavaScript" type="text/javascript"> // global var: which button I am pressing var btnWhichButton;
4
4804
by: John Smith | last post by:
I have a continuous form. there is a command button with the following code for the OnClick event: DoCmd.OpenForm "frmPlants", , , "PlantsID =" & Me!PlantsID I click the button and frmPlants opens up with the record that corresponds to the one on the cont. form. I put that same code for the OnClick of an image control (i.e. the user clicks a little icon to open the form instead of a button) and frmPlants
4
7828
by: martin | last post by:
Hello, Is there a way to make a kind of "cancel" button on a form? Suppose you accidently changed or overwrote some data in a form, then I'd like to leave this form at once and cancel any change made in this form. Hopefully someone has a clue for me. thanks a lot!
8
19181
by: =?Utf-8?B?UmljaA==?= | last post by:
My from contains a "Move Next" button. When the user clicks on the "Move Next" button - several procedures get invoked and eventually, the dataset underlying the form will display main data from the next record and will display detail data in a datagridview also on the form which is related to the current main record in view. Another button ("Transfer Account") on the form can modify what detail data is related to the current main...
0
9680
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
10456
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
10012
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...
0
9052
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7548
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
5442
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...
0
5575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2926
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.