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
> How To Handle A Form Save That's The 1st Step Of Command Button?, Access 2003    
 
   
whdyck
post Jun 20 2019, 09:40 AM
Post#1



Posts: 323
Joined: 20-July 11
From: Winnipeg, MB, Canada


I have a command button's Click event handler that looks like this:

CODE
Private Sub cmdIssueUnit_Click()
On Error GoTo cmdIssueUnit_ClickErr

    Me.Dirty = False

    {other stuff to do}

cmdIssueUnit_ClickBye:
    Exit Sub

cmdIssueUnit_ClickErr:
    Select Case Err.Number
        Case Else
            MsgBoxErr Me.Name, "cmdIssueUnit_Click", , Me
    End Select
    Resume cmdIssueUnit_ClickBye
End Sub

When "Me.Dirty = False" fires, Form_BeforeUpdate() contains code that checks whether the form can be saved and displays a message (and sets Cancel = True) if it cannot. However, even if Form_BeforeUpdate() cancels the update, immediately after the "Me.Dirty = False" statement, execution moves to cmdIssueUnit_ClickErr and a 2nd error displays ("Error 2101: The setting you entered isn't valid for this property").

I could make the 2nd message go away by using a Case 2101 in the error-handling block and ignoring that error. But is that the way I should be doing this?

In general, how should I handle a cmd_Click event that first saves the record? Or should code require the user to explicitly save before clicking the command button?

Thanks for any help you can give.

Wayne
Go to the top of the page
 
theDBguy
post Jun 20 2019, 10:35 AM
Post#2


Access Wiki and Forums Moderator
Posts: 76,379
Joined: 19-June 07
From: SunnySandyEggo


Hi. If you're sure the BeforeUpdate event can handle all scenarios so you can ignore the error, then handling it would be fine. Otherwise, you can try adding a flag to check if the BeforeUpdate event was successful or not and act/proceed accordingly.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
whdyck
post Jun 20 2019, 11:13 AM
Post#3



Posts: 323
Joined: 20-July 11
From: Winnipeg, MB, Canada


Thanks. That helps.

Wayne
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    15th October 2019 - 06:44 AM