By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,086 Members | 1,452 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,086 IT Pros & Developers. It's quick & easy.

auto generate claim no

P: n/a
Dear Gurus,

i had written following codes to auto generate the next claim no

Private Const strC = "GCT/02/J/"
Private Sub Command1_Click()
Dim stra, stre As String
Dim intb, intd As Integer
Dim strd As String
stra = "200"
intb = Val(stra) + 1
intd = Len(CStr(intb))
stre = String(4 - intd, "0") & CStr(intb)
MsgBox strC & stre
End Sub

now the issue is that based on last claim no. when the forms load, we
wants to generate a new no and insert table/add as new record. say we
have serial

GCT/02/J/001,GCT/02/J/002,GCT/02/J/003...SO ON so the new ID will be
GCT/02/J/004
so can any one put highlights how to do this...

regards,
shahzad

Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

SalimShahzad wrote:
Dim stra, stre As String
Dim intb, intd As Integer
BTW - with the above, you'll declare stra and intb as variants. Your way is
feasible with i.e. VB.Net but not with VBA/VB...6. There you'll have to
define each variable even if they're delimited by a comma, as in:

Dim stra As String, stre As String
Dim intb As Integer, intd As Integer
now the issue is that based on last claim no. when the forms load, we
wants to generate a new no and insert table/add as new record. say we
have serial

GCT/02/J/001,GCT/02/J/002,GCT/02/J/003...SO ON so the new ID will be
GCT/02/J/004
so can any one put highlights how to do this...


Basically, I'd solve that with something like this:

Function getNext(ByVal strLast As String) As String
Dim strLeaveAlone As String
Dim intNextNo As Integer
strLeaveAlone = Left(strLast, Len(strLast) - _
InStr(1, StrReverse(strLast), "/") + 1)
intNextNo = CInt(Mid(strLast, Len(strLeaveAlone) + 1))
getNext = strLeaveAlone & Format(intNextNo + 1, "000")
End Function

The above will use the last occurance of "/" to find the numeric part.
You might also want to check out the split-function (in your case,
split(strLast, "/")(3) would give you the numeric part at the end) which is
available from A2K on (as is the strReverse-function).

Cheers,
Olaf [MVP]
--
My .02: www.Resources.IntuiDev.com
Nov 13 '05 #2

P: n/a
On 2 Feb 2005 05:00:56 -0800, "SalimShahzad" <sa**********@gmail.com>
wrote:
Dear Gurus,

i had written following codes to auto generate the next claim no

Private Const strC = "GCT/02/J/"
Private Sub Command1_Click()
Dim stra, stre As String
Dim intb, intd As Integer
Dim strd As String
stra = "200"
intb = Val(stra) + 1
intd = Len(CStr(intb))
stre = String(4 - intd, "0") & CStr(intb)
MsgBox strC & stre
End Sub

now the issue is that based on last claim no. when the forms load, we
wants to generate a new no and insert table/add as new record. say we
have serial

GCT/02/J/001,GCT/02/J/002,GCT/02/J/003...SO ON so the new ID will be
GCT/02/J/004
so can any one put highlights how to do this...

regards,
shahzad

I use this to generate the numbers for one of my control logs
since it is a string value you can modify it easily to store the
"GCT/02/J/"

These two functions are in a module Named SerialNumber

Public Function nextNumber() As String
Dim nextSerial As Long
nextSerial = DMax("[CtrlNumber]", "tblSource") + 1
nextNumber = nextSerial
End Function

Public Function nextLogNbr() As String
nextLogNbr = nextNumber() & "-" & Right(Year(Date), 2)
End Function

The data entry form for tblSource onLoad event is
DoCmd.GoToRecord , , acNewRec

The data entry form for tblSource uses Three text boxes to record the
log number data, all have auto tab and tab stop set to no

a text box with the
control source = CtrlNumber
default value =nextNumber()
visable no

The LogNumber Text box
Control source = MstrLogNum
Default Value = nextLogNbr()
visable no

An unbound Text box
Control source
Default Value = nextLogNbr()
visable yes
Background color same as the form background
style flat

this allows the user to see the number (it looks like a lable but
should they click on it and type any data into it it has no effect on
the table.
Have a nice day. ld****@NOPANTS.juno.com

Remove NOPANTS. To reply by direct E-Mail;
Support: The Right to Privacy and Anti-SPAM projects
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.