PC Review


Reply
Thread Tools Rate Thread

Duplicated Invoice number checking when leave the field

 
 
aw
Guest
Posts: n/a
 
      14th May 2010
I have a FORM to input NEW invoice information.

How can I write code for prompt user of duplicate invoice number being
inputted (under the form) when user leave this field IMMEDIATELY

(rather than my existing one do this when all information already input and
prompt you at the time of saving)

--
aw
 
Reply With Quote
 
 
 
 
Allen Browne
Guest
Posts: n/a
 
      14th May 2010
Private Sub InvoiceID_BeforeUpate(Cancel As Integer)
Dim strWhere As String
Dim strMsg As String
Dim varResult As Variant

With Me.[InvoiceID]
If Me.NewRecord And Not IsNull(.Value)
strWhere = "[InvoiceID] = " & .Value
varResult = DLookup("InvoiceID", "tblInvoice", strWhere)
If Not IsNull(varResult) Then
Cancel = True
strMsg = "That invoice number already exists." & vbCrLf & _
"Enter a different number, or press "<Esc> to undo."
MsgBox strMsg, vbExclamation, "Duplicate"
End If
End If
End With
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"aw" <(E-Mail Removed)> wrote in message
news:AED2419D-70A6-451F-8E11-(E-Mail Removed)...
> I have a FORM to input NEW invoice information.
>
> How can I write code for prompt user of duplicate invoice number being
> inputted (under the form) when user leave this field IMMEDIATELY
>
> (rather than my existing one do this when all information already input
> and
> prompt you at the time of saving)
>
> --
> aw


 
Reply With Quote
 
Al Campagna
Guest
Posts: n/a
 
      14th May 2010

"aw" <(E-Mail Removed)> wrote in message
news:AED2419D-70A6-451F-8E11-(E-Mail Removed)...
>I have a FORM to input NEW invoice information.
>
> How can I write code for prompt user of duplicate invoice number being
> inputted (under the form) when user leave this field IMMEDIATELY
>
> (rather than my existing one do this when all information already input
> and
> prompt you at the time of saving)
>
> --
> aw



 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      14th May 2010
On Thu, 13 May 2010 19:15:01 -0700, aw <(E-Mail Removed)> wrote:

>I have a FORM to input NEW invoice information.
>
>How can I write code for prompt user of duplicate invoice number being
>inputted (under the form) when user leave this field IMMEDIATELY
>
>(rather than my existing one do this when all information already input and
>prompt you at the time of saving)


If the user is manually entering the invoice number into txtInvoiceNo, you can
use the BeforeUpdate event of txtInvoiceNo (not the event of the Form):

Private Sub txtInvoiceNo_BeforeUpdate(Cancel as Integer)
If Not IsNull(DLookUp("InvoiceNo", "Invoices", _
"[InvoiceNo] = '" & Me!txtInvoiceNo & "'") Then
MsgBox "This invoice number has been used"
Cancel = True
<any other appropriate actions>
End If
End Sub
--

John W. Vinson [MVP]
 
Reply With Quote
 
Al Campagna
Guest
Posts: n/a
 
      14th May 2010
aw,
Several ways to do that. One would be...
Your InvoiceNo should be a unique value key field.
In your table design, make it...
Indexed - No Duplicates
Use the AfterUpdate event of InvoiceID to
Refresh
the form, and trigger an Access "Duplicate Value" error.

Or... use the InvoiceID BeforeUpdate event to do a DLookup of the just
entered value, to see if it matches any previous values. If so,
post a custom message to the user that the InvoiceID is a Dupe, and ...
Cancel = True
InvoiceID.Undo
--
hth
Al Campagna
Microsoft Access MVP 2007-2009
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."

"aw" <(E-Mail Removed)> wrote in message
news:AED2419D-70A6-451F-8E11-(E-Mail Removed)...
>I have a FORM to input NEW invoice information.
>
> How can I write code for prompt user of duplicate invoice number being
> inputted (under the form) when user leave this field IMMEDIATELY
>
> (rather than my existing one do this when all information already input
> and
> prompt you at the time of saving)
>
> --
> aw



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
invoice toolbar for invoice calcuation and assign number =?Utf-8?B?S2FyZW5Z?= Microsoft Excel Misc 16 16th Mar 2007 12:02 PM
How do I assign an invoice number using the invoice toolbar? =?Utf-8?B?U2hhcm9u?= Microsoft Excel Worksheet Functions 1 23rd Dec 2006 09:32 AM
How do I generate a new invoice number when creating new invoice? =?Utf-8?B?S2lkZGllV29uZGVybGFuZA==?= Microsoft Excel Misc 1 15th Mar 2006 03:19 AM
How do I change the invoice number assigned in Invoice template... =?Utf-8?B?YWtyZXNz?= Microsoft Excel Misc 1 28th Feb 2005 06:36 PM
Invoice Template with Autoupdate for Invoice Number Barb Reinhardt Microsoft Word Document Management 2 10th Dec 2004 08:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:57 PM.