Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 02-02-2019, 11:13 AM   #1
helmerr
Newly Registered User
 
Join Date: Nov 2013
Posts: 140
Thanks: 33
Thanked 0 Times in 0 Posts
helmerr is on a distinguished road
Answer 'No' to Save produces error

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?
Attached Files
File Type: zip FleetRequisitions.zip (206.6 KB, 19 views)

helmerr is offline   Reply With Quote
Old 02-02-2019, 11:31 AM   #2
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 6,467
Thanks: 58
Thanked 1,413 Times in 1,394 Posts
theDBguy has a spectacular aura about theDBguy has a spectacular aura about
Re: Answer 'No' to Save produces error

Hi. I'd say just add an error handler to your code and move on.
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is online now   Reply With Quote
Old 02-02-2019, 12:58 PM   #3
helmerr
Newly Registered User
 
Join Date: Nov 2013
Posts: 140
Thanks: 33
Thanked 0 Times in 0 Posts
helmerr is on a distinguished road
Re: Answer 'No' to Save produces error

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?

helmerr is offline   Reply With Quote
Old 02-02-2019, 01:01 PM   #4
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 6,467
Thanks: 58
Thanked 1,413 Times in 1,394 Posts
theDBguy has a spectacular aura about theDBguy has a spectacular aura about
Re: Answer 'No' to Save produces error

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
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is online now   Reply With Quote
The Following User Says Thank You to theDBguy For This Useful Post:
helmerr (02-02-2019)
Old 02-02-2019, 02:43 PM   #5
helmerr
Newly Registered User
 
Join Date: Nov 2013
Posts: 140
Thanks: 33
Thanked 0 Times in 0 Posts
helmerr is on a distinguished road
Re: Answer 'No' to Save produces error

Thanks! That did it.
helmerr is offline   Reply With Quote
Old 02-02-2019, 03:15 PM   #6
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 6,467
Thanks: 58
Thanked 1,413 Times in 1,394 Posts
theDBguy has a spectacular aura about theDBguy has a spectacular aura about
Re: Answer 'No' to Save produces error

You’re welcome. Good luck with your project.
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is online now   Reply With Quote
Old 02-02-2019, 09:08 PM   #7
June7
AWF VIP
 
June7's Avatar
 
Join Date: Mar 2014
Location: The Great Land
Posts: 2,451
Thanks: 0
Thanked 571 Times in 567 Posts
June7 will become famous soon enough June7 will become famous soon enough
Re: Answer 'No' to Save produces error

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.

__________________
Attach File Manager is below Advanced editor window, click Go Advanced below Quick Reply window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
DEBUG! DEBUG! DEBUG!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by June7; 02-02-2019 at 09:43 PM.
June7 is offline   Reply With Quote
The Following User Says Thank You to June7 For This Useful Post:
helmerr (02-03-2019)
Old 02-03-2019, 05:00 AM   #8
helmerr
Newly Registered User
 
Join Date: Nov 2013
Posts: 140
Thanks: 33
Thanked 0 Times in 0 Posts
helmerr is on a distinguished road
Re: Answer 'No' to Save produces error

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
helmerr is offline   Reply With Quote
Old 02-03-2019, 11:58 AM   #9
June7
AWF VIP
 
June7's Avatar
 
Join Date: Mar 2014
Location: The Great Land
Posts: 2,451
Thanks: 0
Thanked 571 Times in 567 Posts
June7 will become famous soon enough June7 will become famous soon enough
Re: Answer 'No' to Save produces error

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.

__________________
Attach File Manager is below Advanced editor window, click Go Advanced below Quick Reply window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
DEBUG! DEBUG! DEBUG!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
June7 is offline   Reply With Quote
Reply

Tags
2105 , error , prompt , save , vba

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Relinking to SQL Server View produces error djoosten SQL Server 7 01-06-2017 07:44 AM
event property setting produces error exaccess Forms 2 11-24-2014 09:26 AM
Mode function using WorksheetFunction produces error GKIL67 Modules & VBA 1 02-19-2013 08:32 PM
AfterUpdate produces error chris klein Forms 17 11-06-2008 01:08 PM
Running Excel macro produces error snowsride Modules & VBA 0 11-02-2006 08:19 AM




All times are GMT -8. The time now is 01:42 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World