Answer 'No' to Save produces error (1 Viewer)

helmerr

Registered User.
Local time
Today, 14:34
Joined
Nov 27, 2013
Messages
140
The code from the link below prompts a user to save the current record before changing records if the form is dirty. I've put this code in my form, but it produces an error anytime I select No to not save the record.


For instance, in a new record on the form, type something in any field and hit the new button. Answering no to the save prompt produces run-time error 2105 "You can't go to the specified record," which then highlights the DoCmd.GoToRecord , , acNewRec from the new button.



http://www.databasedev.co.uk/prompt_to_save.html


It's a simple form and I've uploaded it to this post. Can someone please assist?
 

Attachments

theDBguy

I’m here to help
Local time
Today, 11:34
Joined
Oct 29, 2018
Messages
10,819
Hi. I'd say just add an error handler to your code and move on.
 

helmerr

Registered User.
Local time
Today, 14:34
Joined
Nov 27, 2013
Messages
140
Hanks doe your response. Does that mean it would just bypass that portion of the code if the user answers no? Everything appears to work ok otherwise.

I’ve never just wrote error handling. Could you provide some assistance?
 

theDBguy

I’m here to help
Local time
Today, 11:34
Joined
Oct 29, 2018
Messages
10,819
In the click event of your "New" button, try something like:
Code:
Private Sub cmdNew_Click()
On Error GoTo errHandler

    ' Clear combobox
    Me.cboBrowse = ""

    'New Record
    DoCmd.GoToRecord , , acNewRec

errExit:
    Exit Sub
    
errHandler:
    If Err.Number <> 2105 Then
        MsgBox Err.Number & ". " & Err.Description
    End If
    Resume errExit
    
End Sub
 

theDBguy

I’m here to help
Local time
Today, 11:34
Joined
Oct 29, 2018
Messages
10,819
You’re welcome. Good luck with your project.
 

June7

AWF VIP
Local time
Today, 10:34
Joined
Mar 9, 2014
Messages
3,134
Following code works:
Code:
    'New Record
    If Me.NewRecord Then
        DoCmd.RunCommand acCmdSaveRecord
    Else
        DoCmd.GoToRecord , , acNewRec
    End If
Looking at the BeforeUpdate event. I think testing for Dirty is unnecessary. Certainly the record must be dirty. Why else would BeforeUpdate fire? But suppose it doesn't hurt.

Multiple similar name fields indicates a non-normalized data structure. It will be more difficult to add up total cost for each requisition. There will be lots of empty cells when less than 15 parts and if you need more than 15 parts the structure does not readily accommodate.
 
Last edited:

helmerr

Registered User.
Local time
Today, 14:34
Joined
Nov 27, 2013
Messages
140
This particular form will rarely be used; it was a replacement for one built with MS works. I'm not sure how to insert rows dynamically so I kept it as is. However if you can be so kind as to point me in the right direction I'd like to check into it. Thanks
 

June7

AWF VIP
Local time
Today, 10:34
Joined
Mar 9, 2014
Messages
3,134
Data appears to be many-to-many relationship - each requisition can have many parts and each part can associate with many requestions. So instead of the 15 sets of Part Qty/Desc/Cost fields, there would be tables:

tblParts
PartID
PartDesc
PartCost

tblRequisionParts
ReqID_FK
PartID_FK
Quantity

Should probably be something similar for the 11 Cost___ fields but not clear what that data is.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom