By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Sub Forms

P: 38
Hello, I have a question, I have an employee table with an attendance subform linked through the Employee ID. I didn't not build this database which is why I don't really want to change the structure of the database. What I want to do is add a button to go to the last record on the subform. Only problem is that the person who created it, made the subform as a database sheet so I can't add it on the subform because it only shows the datasheet. I need to add a button on the employee form that will go to the last record on the subform. Can anyone help me with this?
Thank you
Sep 10 '08 #1
Share this Question
Share on Google+
10 Replies


puppydogbuddy
Expert 100+
P: 1,923
Place this code on the Main Form. Replace the illustrative object names (YourButton, YourSubformControl) with their actual names.

Expand|Select|Wrap|Line Numbers
  1. Private Sub YourButton_Click()
  2. On Error GoTo Error_Routine
  3.  
  4. Me.YourSubformControl.Form!EmployeeID.SetFocus    
  5. DoCmd.GoToRecord , , acLast
  6.  
  7.  
  8. Exit_Continue:
  9.     Exit Sub
  10.  
  11. Error_Routine:
  12.     MsgBox "Error# " & Err.Number & " " & Err.Description
  13.     Resume Exit_Continue
  14. End Sub
Sep 12 '08 #2

P: 38
Place this code on the Main Form. Replace the illustrative object names (YourButton, YourSubformControl) with their actual names.

Expand|Select|Wrap|Line Numbers
  1. Private Sub YourButton_Click()
  2. On Error GoTo Error_Routine
  3.  
  4. Me.YourSubformControl.Form!EmployeeID.SetFocus    
  5. DoCmd.GoToRecord , , acLast
  6.  
  7.  
  8. Exit_Continue:
  9.     Exit Sub
  10.  
  11. Error_Routine:
  12.     MsgBox "Error# " & Err.Number & " " & Err.Description
  13.     Resume Exit_Continue
  14. End Sub
Thank you for your response; however, I am getting error#0 from Access, is there a reason?
Sep 12 '08 #3

puppydogbuddy
Expert 100+
P: 1,923
Thank you for your response; however, I am getting error#0 from Access, is there a reason?
Did you Replace the illustrative object names (YourButton, YourSubformControl) with their actual names as discussed?

Does the property sheet for YourButton_Click event show the words "EventProcedure"?

Did you compile your code without error?
Sep 12 '08 #4

P: 38
Did you Replace the illustrative object names (YourButton, YourSubformControl) with their actual names as discussed?

Does the property sheet for YourButton_Click event show the words "EventProcedure"?

Did you compile your code without error?
I did change them, this is what I inserted:

Me.EmployeeFMActivityLogSDS.Form!ActionDate.SetFoc us
DoCmd.GoToRecord , , acLast

Error_Routine:

MsgBox "Error# " & Err.Number & " " & Err.Description

It says "EventProcedure", I just can't understand why it doesn't work. The code seems good. I did complie it and it complied without error. But I am still receiving error # 0. Any thoughts? Thanks again for your help!
Sep 12 '08 #5

puppydogbuddy
Expert 100+
P: 1,923
I did change them, this is what I inserted:

Me.EmployeeFMActivityLogSDS.Form!ActionDate.SetFoc us
DoCmd.GoToRecord , , acLast

Error_Routine:

MsgBox "Error# " & Err.Number & " " & Err.Description

It says "EventProcedure", I just can't understand why it doesn't work. The code seems good. I did complie it and it complied without error. But I am still receiving error # 0. Any thoughts? Thanks again for your help!

Looking at what you posted above, you left out lines 2,8, 9 and 13 of the code I gave you. That code needs to be there to prevent error 0.

Is EmployeeFMActivityLogSDS the name of your subform control on the Main form?

If it is, try this:
Me!EmployeeFMActivityLogSDS.Form!ActionDate.SetFoc us
Sep 12 '08 #6

P: 38
Looking at what you posted above, you left out lines 2,8, 9 and 13 of the code I gave you. That code needs to be there to prevent error 0.

Is EmployeeFMActivityLogSDS the name of your subform control on the Main form?

If it is, try this:
Me!EmployeeFMActivityLogSDS.Form!ActionDate.SetFoc us
EmployeeFMActivityLogSDS Is the name of the subform. I was leaving out row 13. I had the other rows, I just forgot to insert them. That did work however, it sets focus correctly, but it goes to the last record on the main form not the subform. Everything else works well, but I need it go to the last record of the subform. Thank you very much!
Sep 12 '08 #7

puppydogbuddy
Expert 100+
P: 1,923
EmployeeFMActivityLogSDS Is the name of the subform. I was leaving out row 13. I had the other rows, I just forgot to insert them. That did work however, it sets focus correctly, but it goes to the last record on the main form not the subform. Everything else works well, but I need it go to the last record of the subform. Thank you very much!

change this:
DoCmd.GoToRecord , , acLast

To this:
DoCmd.RunCommand acCmdRecordsGoToLast
Sep 12 '08 #8

P: 38
change this:
DoCmd.GoToRecord , , acLast

To this:
DoCmd.RunCommand acCmdRecordsGoToLast
Still the same, for some reason it sets focus, but goes to the last record of the main form.
Sep 12 '08 #9

puppydogbuddy
Expert 100+
P: 1,923
Still the same, for some reason it sets focus, but goes to the last record of the main form.
OK, try it this way (sets focus on subform control):

Me!EmployeeFMActivityLogSDS.SetFocus
DoCmd.RunCommand acCmdRecordsGoToLast
Sep 12 '08 #10

P: 38
OK, try it this way (sets focus on subform control):

Me!EmployeeFMActivityLogSDS.SetFocus
DoCmd.RunCommand acCmdRecordsGoToLast
That worked perfectly! Thank you very much! I appreciate all of your help!
Sep 12 '08 #11

Post your reply

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