A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Goto new record of subform and force a save using the default values ?



 
 
Thread Tools Display Modes
  #1  
Old March 13th, 2007, 07:58 AM posted to microsoft.public.access.forms
Richard
external usenet poster
 
Posts: 17
Default Goto new record of subform and force a save using the default values ?

Experts:

A bound form X contains a bound subform Y and they are linked via
Child/Master settings.

UF is an unbound form that contains subform X and a command button
"New"

When new is clicked the event handler does
Me.X.Field1.DefaultValue = """New Field 1"""
Me.X.Field2.DefaultValue = """New Field 2"""
Me.X.Field3.DefaultValue = """New Field 3"""
Me.X.SetFocus
DoCmd.GoToRecord , , acNewRec

The new record is gone to, and the default values are shown as
expected. But the record does not get written to tblX.

How can I force the new record to get written to the table ?

Thanks,

  #2  
Old March 13th, 2007, 08:08 AM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default Goto new record of subform and force a save using the default values ?

You could dirty the record by assigning the existing (default) value to a
control, and then saving:

With Me.X.Form
!Field1 = !Field1
.Dirty = False
End With

If you just wanted a new record added, it might be easier to AddNew to its
RecordsetClone, and then display that record:

Dim rs As DAO.Recordset
With Me.X.Form
Set rs = .RecordsetClone
rs.AddNew
rs!Field1 = "New Field 1"
rs!Field2 = "New Field 2"
'etc
rs.Update
.Bookmark = rs.LastModified
Set rs = Nothing
End With

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Richard" wrote in message
oups.com...
Experts:

A bound form X contains a bound subform Y and they are linked via
Child/Master settings.

UF is an unbound form that contains subform X and a command button
"New"

When new is clicked the event handler does
Me.X.Field1.DefaultValue = """New Field 1"""
Me.X.Field2.DefaultValue = """New Field 2"""
Me.X.Field3.DefaultValue = """New Field 3"""
Me.X.SetFocus
DoCmd.GoToRecord , , acNewRec

The new record is gone to, and the default values are shown as
expected. But the record does not get written to tblX.

How can I force the new record to get written to the table ?

Thanks,


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:40 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.