473,385 Members | 2,180 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,385 software developers and data experts.

Button points to a record in form

16
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 1640
patjones
931 Expert 512MB
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 Expert 100+
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 Expert 512MB
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
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...
1
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...
3
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...
1
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">...
14
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...
1
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...
4
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...
4
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...
8
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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$) { } ...
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...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.