Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 27th, 2005, 01:04 PM
Authorized User
 
Join Date: Apr 2005
Location: , , USA.
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default Yes No Message box

Hello,

I use a command button to post an invoice amount. I would like to prevent accidental overwriting of a current invoice amount. This code overwrites the amount even after clicking “No”. I would like the cancel the action when “No’ is clicked. Please help!


Private Sub PostInvoice_Click()
On Error GoTo Err_PostInvoice_Click

If IsNull(InvoiceBalance) Then
    [InvoiceTotal] = Me.InvoiceTotal1
    [InvoiceBalance] = Me.InvoiceTotal1
    [DueDate] = Me.InvoiceDate + 30

Else
    MsgBox "You are about to overwrite the current invoice balance"

MsgBox "Are you sure you want to overwrite the current invoice amount", vbYesNo
        If vbYes Then
            [InvoiceTotal] = Me.InvoiceTotal1
            [InvoiceBalance] = Me.InvoiceTotal1
            [DueDate] = Me.InvoiceDate + 30
        Else
            Exit Sub

        End If

End If


Exit_PostInvoice_Click:
    Exit Sub

Err_PostInvoice_Click:
    MsgBox Err.Description
    Resume Exit_PostInvoice_Click

End Sub


D. Bartelt
__________________
D. Bartelt
  #2 (permalink)  
Old October 27th, 2005, 01:09 PM
Friend of Wrox
 
Join Date: Jan 2005
Location: Kansas City, Missouri, USA.
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

Howdy D!
How you doing? Switch your code to this:

myresponse = MsgBox("Are you sure you want to overwrite the current invoice amount", vbYesNo)

If myresponse = vbYes Then

Kevin


dartcoach
  #3 (permalink)  
Old October 27th, 2005, 01:10 PM
Friend of Wrox
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Hi,

Try this... What is happening is that you are not capturing the users answer from the Message Box

Original Code


MsgBox "Are you sure you want to overwrite the current invoice amount", vbYesNo
        If vbYes Then
            [InvoiceTotal] = Me.InvoiceTotal1
            [InvoiceBalance] = Me.InvoiceTotal1


New Code


intResponse = MsgBox ("Are you sure you want to overwrite the current invoice amount", vbYesNo+vbQuestion)
'+vbQuestion just adds a Question Mark to the MsgBox
If intResponse = vbYes Then
    [InvoiceTotal] = Me.InvoiceTotal1
    [InvoiceBalance] = Me.InvoiceTotal1
    .......


Hope that helps,

Mike

Mike
EchoVue.com
  #4 (permalink)  
Old October 27th, 2005, 01:47 PM
Authorized User
 
Join Date: Apr 2005
Location: , , USA.
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi dartcoach,

I'm doing fine, how 'bout yourself? Thank you for the help. The code worked after I added "Dim myreponse As Integer" to the beginning of the code.

I'm almost done with the accounts receivable database. Just have to figure out how to update the invoice balance field in tblInvoices from the payments subform. The payments subforms' recordsource is tblpayments. Also have to create Aged Receivables forms and reports yet. After those, it's ready to go.

Take care!




D. Bartelt
  #5 (permalink)  
Old October 27th, 2005, 08:30 PM
Friend of Wrox
 
Join Date: Jan 2005
Location: Kansas City, Missouri, USA.
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

D,

Are the tblpayments and tblinvoices related by invoice number?

If they are, then whenever you enter a payment, you would want to recalculate the total payments made, then, update current balance of the invoice where invoice numbers are equal.

Make sense?

Kevin

dartcoach
  #6 (permalink)  
Old October 28th, 2005, 07:01 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Code:
    Dim intUpdate as Integer

    If IsNull(Me.InvoiceBalance) Then
        intUpdate = vbYes
    Else
        intUpdate = MsgBox("You are about to overwrite the current invoice balance.  Are you sure you want to do this?", vbQuestion + vbYesNo, "Overwrite Balance?")
    End If

    If intUpdate = vbYes Then
        Me.InvoiceTotal = Me.InvoiceTotal1
        Me.InvoiceBalance = Me.InvoiceTotal1
        Me.DueDate = DateAdd("d", 30, Me.InvoiceDate)
    End If

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
  #7 (permalink)  
Old October 28th, 2005, 08:05 AM
Authorized User
 
Join Date: Apr 2005
Location: , , USA.
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Kevin,

Yes the tables are related by InvoiceID. InvoiceID is the PK in tblInvoices.

Thanks,

Don

D. Bartelt
  #8 (permalink)  
Old October 28th, 2005, 08:16 AM
Authorized User
 
Join Date: Apr 2005
Location: , , USA.
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default

echovue & SerranoG,

Thanks for your input. I am absorbing all the help I get.

Thanks again!

Don

D. Bartelt


Similar Threads
Thread Thread Starter Forum Replies Last Post
Message box basie Classic ASP Basics 1 September 4th, 2008 01:09 PM
Message box in C# shikha09 C# 0 November 28th, 2006 01:24 AM
how to use message box? andy hee ASP.NET 1.0 and 1.1 Basics 1 April 18th, 2006 04:53 AM
message box nalla ASP.NET 2.0 Professional 4 December 23rd, 2005 03:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.