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

Sub Form record Access/navigatiion

Hi

I have a form/subform where a new record is created on the subform by a
button click.

After the new record is created, I then need to go directly and display
the new record in the subform.

My current code is:-

Private Sub cmdPanelInfoOnly_Click()
On Error GoTo Err_cmdPanelInfoOnly_Click
Dim strSql As String
Dim dbs As Database
Dim rsEpis As Recordset
Dim intPat As Integer

Set dbs = CurrentDb()

strSql = "Select Max([Episode ID]) as MaxId from Episode;"

Set rsEpis = dbs.OpenRecordset(strSql)
[EpisID] = rsEpis.Fields("MaxId").Value + 1

DoCmd.SetWarnings False
intPat = [Patient ID].Value
DoCmd.OpenQuery "qinsEpisodeForPanelOnly" - Inserts the default
values in the new record
DoCmd.SetWarnings True

[Forms]![frmpatient].Form.Filter = "[Patient]![Patient ID] = " & intPat
[Forms]![frmpatient].Form.Requery

'This next bit works, but needs to be sped up!!!!!

Do Until [subfrmEpisode].Form![Patient ID] = [intPat]
DoCmd.GoToRecord , , acNext
Loop

Do Until [subfrmEpisode].Form![Episode ID] = [EpisID]
subfrmEpisode.SetFocus
DoCmd.GoToRecord , , acNext
Loop

Exit_cmdPanelInfoOnly_Click:
Exit Sub

Err_cmdPanelInfoOnly_Click:
MsgBox Err.Description
Resume Exit_cmdPanelInfoOnly_Click

End Sub

I cannot seem to find a more efficient way of navigating directly to
the new sub form record
Can anybody assist please

Thanks

Gary

Oct 3 '06 #1
4 1731
try:
Dim frmS As Form

[Episid] = DMax("MaxId", "Episode") + 1

CurrentDb.Execute "qinsEpisodeForPaelOnly"

Set frmS = Me.subfrmEpisode.form
frmS.Requery

frmS.RecordsetClone.FindFirst "[Patient id] = " & [Episid]
frmS.Bookmark = frmS.RecordsetClone.Bookmark

The above is ALL the code you need.

What I don't see, or understand is how your qinsEpisodeForPanelOnly" knows
what record to work on?
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
Oct 3 '06 #2
Gary, just out of interest, what's the maximum number of Patients you're
forseeably likely to want to store in the database?
ga*********@nhs.net wrote:
>Hi

I have a form/subform where a new record is created on the subform by a
button click.

After the new record is created, I then need to go directly and display
the new record in the subform.

My current code is:-

Private Sub cmdPanelInfoOnly_Click()
On Error GoTo Err_cmdPanelInfoOnly_Click
Dim strSql As String
Dim dbs As Database
Dim rsEpis As Recordset
Dim intPat As Integer

Set dbs = CurrentDb()

strSql = "Select Max([Episode ID]) as MaxId from Episode;"

Set rsEpis = dbs.OpenRecordset(strSql)
[EpisID] = rsEpis.Fields("MaxId").Value + 1

DoCmd.SetWarnings False
intPat = [Patient ID].Value
DoCmd.OpenQuery "qinsEpisodeForPanelOnly" - Inserts the default
values in the new record
DoCmd.SetWarnings True

[Forms]![frmpatient].Form.Filter = "[Patient]![Patient ID] = " & intPat
[Forms]![frmpatient].Form.Requery

'This next bit works, but needs to be sped up!!!!!

Do Until [subfrmEpisode].Form![Patient ID] = [intPat]
DoCmd.GoToRecord , , acNext
Loop

Do Until [subfrmEpisode].Form![Episode ID] = [EpisID]
subfrmEpisode.SetFocus
DoCmd.GoToRecord , , acNext
Loop

Exit_cmdPanelInfoOnly_Click:
Exit Sub

Err_cmdPanelInfoOnly_Click:
MsgBox Err.Description
Resume Exit_cmdPanelInfoOnly_Click

End Sub

I cannot seem to find a more efficient way of navigating directly to
the new sub form record
Can anybody assist please

Thanks

Gary
--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200610/1

Oct 3 '06 #3
Thats great, thanks

What I really want now is to set the focus to the newly added record on
the subform

Thanks

Gary
Albert D. Kallal wrote:
try:
Dim frmS As Form

[Episid] = DMax("MaxId", "Episode") + 1

CurrentDb.Execute "qinsEpisodeForPaelOnly"

Set frmS = Me.subfrmEpisode.form
frmS.Requery

frmS.RecordsetClone.FindFirst "[Patient id] = " & [Episid]
frmS.Bookmark = frmS.RecordsetClone.Bookmark

The above is ALL the code you need.

What I don't see, or understand is how your qinsEpisodeForPanelOnly" knows
what record to work on?
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
Oct 4 '06 #4

<ga*********@nhs.netwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
Thats great, thanks

What I really want now is to set the focus to the newly added record on
the subform
you have to do it in two steps

step 1 - set focus to sub-form control
step 2 - set focus to a field on the sub-form control

so,

me.subfrmEpisode.setfocus

me.subfrmEpsiode.form.NameOfFieldOnForm.setfocus

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
Oct 4 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Neil | last post by:
I have a very puzzling situation with a database. It's an Access 2000 mdb with a SQL 7 back end, with forms bound using ODBC linked tables. At our remote location (accessed via a T1 line) the time...
2
by: Iain Miller | last post by:
Struggling a bit here & would be grateful for any help. I have a table which has a list of people in it. Each person has a unique ID automatically allocated by Access but also belongs to one of 5...
4
by: Skully Matjas | last post by:
I am using the following code (created by the wizard) to allow to bring my form to a particular entery. But when I edit the entery (ex: put new information into a blank cell), it puts that record...
5
by: Steve Strik | last post by:
My Problem: I have created a database here at work that is exhibiting some very strange behaviour. Essentially the database is structured in a manner where one table is a master record table...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
12
by: swingingming | last post by:
Hi, in the NorthWind sample database, when clicking on the next navigation button on the new order record with nothing on the subform (order details), we got an order with nothing ordered. How can...
5
by: ortaias | last post by:
I have a form which calls up a second form for purposes of data entry. When closing the data entry form and returning to the main form, things don't work as expected. When I return to the main...
13
by: kev | last post by:
Hi all, I have created a database for equipments. I have a form to register the equipment meaning filling in all the particulars (ID, serial, type, location etc). I have two buttons at the end...
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: 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
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:
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...
0
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...
0
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,...
0
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...

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.