473,385 Members | 1,769 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.

Subform: Accessing last record

108 100+
Greetings,

I have a main form. Upon filling in a combo box it then displays a subform (based on a query that uses values in the combo box on where clause)

THe subform has the paramater Data Entry = 'No' as I want users to see all existing records and all additions/deletions and edits.

However I want to move to the last record to default, allowing the user to add a record without navigating themselves to the last record.

A popular request, so found code (see below)

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboDeliveryName_AfterUpdate()
  2.  
  3.   Me.qryStudentsResultsDeliverysubform1.Enabled = True
  4.   Me.qryStudentsResultsDeliverysubform1.Visible = True
  5.   Me.qryStudentsResultsDeliverysubform1.SetFocus
  6.  
  7.     With Me.qryStudentsResultsDeliverysubform1.Form.RecordsetClone
  8.        If Not .BOF Then
  9.             .MoveLast
  10.             MsgBox "In here"
  11.             Me.qryStudentsResultsDeliverysubform1.Form.Bookmark = .Bookmark
  12.       End If
  13.     End With
  14.  
  15. End Sub
When testing the subform is populated with 1 or more rows but the debug message is NEVER displayed. If i remove the IF condition it complains with message "3021 : No current record"

I cant even print the current record when im in the subform to see whats happening.

Can anyone please advice and assist?

Thanks
Rob
Feb 21 '08 #1
7 6528
mshmyob
904 Expert 512MB
To jumpt to the last record in a subform after some event you could simplify your code by just doing this:

Expand|Select|Wrap|Line Numbers
  1. Me.subformControlName.SetFocus
  2. DoCmd.GoToRecord , , acLast
  3.  
Note: Going to the last record is NOT the same as adding a new record.

Greetings,

I have a main form. Upon filling in a combo box it then displays a subform (based on a query that uses values in the combo box on where clause)

THe subform has the paramater Data Entry = 'No' as I want users to see all existing records and all additions/deletions and edits.

However I want to move to the last record to default, allowing the user to add a record without navigating themselves to the last record.

A popular request, so found code (see below)

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboDeliveryName_AfterUpdate()
  2.  
  3.   Me.qryStudentsResultsDeliverysubform1.Enabled = True
  4.   Me.qryStudentsResultsDeliverysubform1.Visible = True
  5.   Me.qryStudentsResultsDeliverysubform1.SetFocus
  6.  
  7.     With Me.qryStudentsResultsDeliverysubform1.Form.RecordsetClone
  8.        If Not .BOF Then
  9.             .MoveLast
  10.             MsgBox "In here"
  11.             Me.qryStudentsResultsDeliverysubform1.Form.Bookmark = .Bookmark
  12.       End If
  13.     End With
  14.  
  15. End Sub
When testing the subform is populated with 1 or more rows but the debug message is NEVER displayed. If i remove the IF condition it complains with message "3021 : No current record"

I cant even print the current record when im in the subform to see whats happening.

Can anyone please advice and assist?

Thanks
Rob
Feb 21 '08 #2
robtyketto
108 100+
Thanks.

Added DoCmd.GoToRecord , , acLast to code.

If the subform is populated with 1 ROW then the cursor sits in the new record.

If there is more than 1 ROW then it sits in the first row.
Very strange behaviour.

Rob
Feb 21 '08 #3
mshmyob
904 Expert 512MB
Show the whole code now.

Thanks.

Added DoCmd.GoToRecord , , acLast to code.

If the subform is populated with 1 ROW then the cursor sits in the new record.

If there is more than 1 ROW then it sits in the first row.
Very strange behaviour.

Rob
Feb 21 '08 #4
robtyketto
108 100+
Data entry is set to "No" on subform.

Code from combo box on main form:-

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboDeliveryName_AfterUpdate()
  2.  
  3.     Me.qryStudentsResultsDeliverysubform1.Enabled = True
  4.     Me.qryStudentsResultsDeliverysubform1.Visible = True
  5.     Me.qryStudentsResultsDeliverysubform1.SetFocus
  6.  
  7.     '-- Set Focus to the SubFormControl 1st
  8.     Me.qryStudentsResultsDeliverysubform1.SetFocus
  9.     '-- Now set Focus to the control on SubForm
  10.     Me.qryStudentsResultsDeliverysubform1.Form!txtStudentId.SetFocus
  11.     '-- And now move to the last record
  12.     DoCmd.GoToRecord , , acLast
  13.  
  14. End Sub
Feb 21 '08 #5
mshmyob
904 Expert 512MB
Try moving to the last record and THEN set focus on your control (ie: switch your last 2 lines around). See if that changes anything.

Data entry is set to "No" on subform.

Code from combo box on main form:-

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboDeliveryName_AfterUpdate()
  2.  
  3.     Me.qryStudentsResultsDeliverysubform1.Enabled = True
  4.     Me.qryStudentsResultsDeliverysubform1.Visible = True
  5.     Me.qryStudentsResultsDeliverysubform1.SetFocus
  6.  
  7.     '-- Set Focus to the SubFormControl 1st
  8.     Me.qryStudentsResultsDeliverysubform1.SetFocus
  9.     '-- Now set Focus to the control on SubForm
  10.     Me.qryStudentsResultsDeliverysubform1.Form!txtStudentId.SetFocus
  11.     '-- And now move to the last record
  12.     DoCmd.GoToRecord , , acLast
  13.  
  14. End Sub
Feb 21 '08 #6
robtyketto
108 100+
Same issues.

I've even tried to add a combo box to allow the user to select if they wish to add or not using

Forms!frmModuleResults!qryStudentsResultsDelivery_ subform1.DataEntry = False

Forms!frmModuleResults!qryStudentsResultsDelivery_ subform1.DataEntry = True

I cant even get that right!

I will also use proper naming conventions for my form and not include spaces next time.Using access 2007.
Feb 21 '08 #7
mshmyob
904 Expert 512MB
Can you upload your database file to me.

Just click on edit/delete at the bottom of your last message and you can add an attachment as a ZIP file.

Same issues.

I've even tried to add a combo box to allow the user to select if they wish to add or not using

Forms!frmModuleResults!qryStudentsResultsDelivery_ subform1.DataEntry = False

Forms!frmModuleResults!qryStudentsResultsDelivery_ subform1.DataEntry = True

I cant even get that right!

I will also use proper naming conventions for my form and not include spaces next time.Using access 2007.
Feb 21 '08 #8

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

Similar topics

10
by: Alain Guichaoua | last post by:
Good evening to all Here is my problem : I have a form with a subform. They are linked. When I open the form I would like the subform to reach its last record. I tried the method...
2
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I have a main form with a continuous subform. On the main form I have a text box that references a field on the subform. What I'd like it to do is show the value...
0
by: Carl | last post by:
I have a main form with navigation buttons on it and a label showing for example Record 1 of 15 using recordsetclone on it and eveything works fine. When I move through the records the record...
1
by: sixsoccer | last post by:
I have built a database with a <Mainform> and a <Subform>. My problem is twofold. 1. My subform is set as a continuos form with AllowAddiotions set to NO (ie. a list of Issues to the client on...
4
by: Dave Boyd | last post by:
Hi, I have two very similar forms each with a subform. The main form gets a few fields from the user and passes this back to a query that the subform is bound to. The requery is done when the...
7
by: Sally | last post by:
In a subform that has no records, what is the white area? If a subform has records and you scroll the records, what is the white area after the last record? I would like to be able to click in...
6
by: Sally | last post by:
I need to be able to click in a subform and run code but at the same time I need to be able to scroll the records without running the code. I tried coding the Enter event of the subform control but...
5
by: tdmailbox | last post by:
I have a form with a child form. In the child form there is a list of names that can grow quite large. On the parent form I want to display the first name from the child form. I set up a test...
4
by: aqua404 | last post by:
I know this has been discussed, but I can't find a resolution. I have a subform on a form. The table with the data for the main form has 15,000 records. I am opening and then setting...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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,...
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...

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.