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

Sub Forms

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
10 1256
puppydogbuddy
1,923 Expert 1GB
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
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
1,923 Expert 1GB
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
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
1,923 Expert 1GB
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
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
1,923 Expert 1GB
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
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
1,923 Expert 1GB
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
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

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

Similar topics

19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
3
by: Joshua Russell | last post by:
Hi, Both the methods below open up a windows form called MasterForm. However, one works better than the other. Method 1 opens the form correctly but I don't have any reference to the instance of...
7
by: Mike Bulava | last post by:
I have created a base form that I plan to use throughout my application let call the form form1. I have Built the project then add another form that inherits from form1, I add a few panel controls...
13
by: MD | last post by:
I have been converting a program from VB6 to VB.Net and enhancing it as well. All has been progressing OK although its been hard work. Now, all of a sudden, when I try to execute a ShowDialog()...
15
by: Joshua Kendall | last post by:
I have a script in which it keeps opening the same form instead of only one instance. I also need help with a form that has a password. Where do I put the actual password? can I use a database for...
3
by: Lloyd Sheen | last post by:
I have the following situation: Need a user resizable user control. After much trying with user control I came across the idea of hosting the controls in a form marked as not TopLevel = false. ...
8
by: Stephen Rice | last post by:
Hi, I have a periodic problem which I am having a real time trying to sort. Background: An MDI VB app with a DB on SQL 2000. I have wrapped all the DB access into an object which spawns a...
3
by: Geraldine Hobley | last post by:
Hello, In my project I am inheriting several forms. However when I inherit from a form and add additional subroutines and methods to my inherited form I get all sorts of problems. e.g. I sometimes...
6
by: dbuchanan | last post by:
I have a Windows Forms application that accesses SQL Server 2k from a small local network. The application has been used for weeks on other systmes but a new install on a new machine retruns...
21
by: Dan Tallent | last post by:
In my application I have a form (Customer) that I want to be able to open multiple copies at once. Within this form I have other forms that can be opened. Example: ZipCode. When the user enters...
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...
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
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
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,...
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...

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.