UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Save Record On One Open Form From Another Form, Access 2007    
 
   
youngb
post Jun 19 2019, 04:40 AM
Post#1



Posts: 579
Joined: 2-September 03
From: Galway, Ireland


Hi,

I am using the code below to save a record on the current active form that has the focus,

CODE
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70


but I am wonder is it possible to save the record on a form while it is open from another form,

i.e something like:



CODE
        If isloaded("MY_FORM") Then
                         'Save Record of this form
                 End If



Thanks in Advance for any helpful suggestions

Brian
Go to the top of the page
 
jleach
post Jun 19 2019, 04:48 AM
Post#2


UtterAccess Editor
Posts: 10,020
Joined: 7-December 09
From: St Augustine, FL


Hi - it's an odd scenario, but you can probably do it by setting the form's Dirty property to False. Something like this:

CODE
Forms("OtherFormName").Dirty = False


Setting Dirty to False will trigger a save action on the form, thus accomplishing what you're after.

--------------------
Go to the top of the page
 
Phil_cattivocara...
post Jun 19 2019, 04:52 AM
Post#3



Posts: 303
Joined: 2-April 18



It's a strange question but... this is an answer:
CODE
If Forms("YourFormName").Dirty Then
    Forms("YourFormName").Dirty = False
End If

In the current form we could simply write
CODE
If Me.Dirty Then
    Me.Dirty = False
End If

and I suggest to use this code instead of DoCmd.DoMenuItem ...

--------------------
Please forgive in advance my horrible English.
Go to the top of the page
 
youngb
post Jun 19 2019, 05:51 AM
Post#4



Posts: 579
Joined: 2-September 03
From: Galway, Ireland


Hi Guys,

Admittedly it does seem like an odd/strange one, but I have my 'Valid' reasons!!


that code works great,


CODE
If Forms("YourFormName").Dirty Then
    Forms("YourFormName").Dirty = False
End If


Thanks Again for the help.

Brian

Go to the top of the page
 
gemmathehusky
post Jun 19 2019, 06:15 AM
Post#5


UtterAccess VIP
Posts: 4,723
Joined: 5-June 07
From: UK


you might need some error handling in case the save fails. It's worth testing to see what happens.

eg - a duplicate record, or a blank entry for a "required" field.

--------------------
Dave (Male)

(Gemma was my dog)
Go to the top of the page
 
youngb
post Jun 19 2019, 06:22 AM
Post#6



Posts: 579
Joined: 2-September 03
From: Galway, Ireland


Hi,

yes I have tested and it seems to work good with a sqlServer backend, it is just two fields that I need to read from the record before it is saved on the normal close of the form, but will check to see what errors I will get on a failed save.

Thanks
Brian
Go to the top of the page
 
jleach
post Jun 19 2019, 07:19 AM
Post#7


UtterAccess Editor
Posts: 10,020
Joined: 7-December 09
From: St Augustine, FL


Dirty can be a little weird sometimes... it might not even throw an error if it can't save, but the property could be true after, so:

CODE
With Forms("MyForm")
  If .Dirty = True Then
    .Dirty = False
    If .Dirty = True Then MsgBox "Save Failed" 'but capture any real errors also...
  End If
End With

--------------------
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    18th July 2019 - 11:11 PM