Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 23rd, 2004, 11:28 AM
ItalianLodging ItalianLodging is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Italy
Posts: 9 ItalianLodging User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 36 sec
Reputation Power: 0
Autoincrement field

Hello Iwells (Merry Christmas first of all) I again thank you for your preciouse help
concerning the availability matter.

I have a function that autonumbers my invoice field in my invoice table.
To explain things better the IDInvoice (sorry I have italian terms on my table)
is taken care of the access Auto Number field while I have this function that is called any time
I click on the NewInvoice cmdButton for it in order to get a new invoice number.
Thing is I want to prevent as much as possible any
duplication of the invoices so I have button that freezes the field in my form as well as a control
that I am trying to develop that checks if there is already a number ...

And .... Guess what ...doesn' work

here is what i am working on:

Private Sub cmdNuovafattura_Click() ' click here and I get a new Invoice number: it works
Me![strNumFatt] = NuovaFattura()
Me![curImporto].SetFocus ' move the focus over the money field
Me![cmdNuovafattura].Enabled = False
End Sub

Public Function NuovaFattura() As Long

If Me![strNumFatt] < 1 Then
'Find highest NumeFattura in the tblDettFatture table and add 1
Aggiungi = DMax("[strNumFatt]", "tblfatture") + 1
'Assign function the value of the NuovoNum
NuovaFattura = Aggiungi
Exit Function

ElseIf Me![strNumFatt] >= 1 Then
MsgBox " You ahve already a number for this invoice "
End If

End Function

I want to have full control over the number of the invoices

Reply With Quote
  #2  
Old December 23rd, 2004, 01:33 PM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 4
Hi ItalianLodging

Just a couple of things here first.

1) Your variable Aggiungi wasn't declared or at least not in your post. That will have to be corrected.
2) You are only checking to see if an invoice number is less than 1 and if true, will generate a new number based on the max number + 1. I am assuming that you want to generate a new invoice number if it is a new record otherwise display a message that an invoice number already exists.

So to simplify your code you might just write it this way.

Private Sub cmdNuovafattura_Click()
If Not IsNull(strNumFatt) Then
MsgBox " You have already a number for this invoice "
Else
strNumFatt.Value = DMax("[strNumFatt]", "tblfatture") + 1
End If
Me![curImporto].SetFocus
Me![cmdNuovafattura].Enabled = False
End Sub

This will display a message box if a number already exists. If the invoice number is Null, it will create a new invoice number one higher than the highest number in your table. Just set the properties to the field strNumFatt to No Duplicates and the default value as Null (Blank)

The code you have already written should work after you have declared your variable or use the sample one I made here.

Merry Christmas,
lwells

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > Autoincrement field


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway