Hi All, VB 6.0 and MS Access
While Saving Record, I want Number to be Generated in following Format
140208-001, 140208-002, 140208-003 . . . etc...
You must have noticed that 140208 is today's Date and After the - Last 3 digits are number.
Now what I want is, lets say If i save 87 Records today it should be 140208-087 and next day (tomorrow) numbers should be like 150208-001, 150208-002 etc.....
Please let me know if it possible then how? I m using the following code for Auto Generation of the Number but in different format.
=========My Code Goes Here =========
Dim C, E As String
Dim D As Integer
C = "ABCDEF"
If Xrs.RecordCount = 0 Then
D = 1
Do While Not Xrs.EOF
If Xrs("QNo") > D Then
End If
Xrs.MoveNext
D = D + 1
Loop
If D >= 1 And D < 10 Then
E = C & "0000" & D
Text1.Text = E
Else
If D >= 10 And D < 100 Then
E = C & "000" & D
Text1.Text = E
Else
If D >= 100 And D < 1000 Then
E = C & "00" & D
Text1.Text = E
Else
If D >= 1000 And D < 10000 Then
E = C & "0" & D
Text1.Text = E
Else
E = C & D
Text1.Text = E
End If
End If
End If
End If
Xrs.AddNew
Xrs("QNo").Value = E
Text1.Text = Xrs.Fields("QNo")
====== Code Ends Here ===========
Regards,
Hiren
13 12027
For the first part use system date . You just need to format the date.
For the second part findout the number of records inserted in that day .You number should be +1.
Next you need to format it as desired.
You need to Store a date field in your table.
QVeen72 1,445
Recognized Expert Top Contributor
Hi,
Code Something like this : -
Dim NextNum As String
-
Dim TNo As Integer
-
Dim RST As New ADODB.RecordSet
-
Dim sSQL As String
-
NextNum = Format(Date, "ddmmyy")
-
sSQL = "Select Max(MyField) From MyTable Where MyField Like '" _
-
& NextNum & "*'"
-
RST.Open sSQL,Conn,adOpenStatic,adOpenLockReadOnly
-
TNo = 0
-
If Not RST.EOF Then
-
RST.MoveFirst
-
sSQL = Trim(RST(0) & "")
-
If Trim(sSQL) <> "" Then
-
TNo = Val(Right(sSQL,3))
-
End If
-
RST.Close
-
End If
-
TNo = TNo +1
-
NextNum = NextNum & "-" & Format(TNo,"000")
-
Regards
Veena
Yes I thought of the same thing, but having confusion of how to Increment Daily Records... I mean how to check If today it is the first record or 5th or 87th?
I am going to try it today, if you can give me any suggestion on above will be helpful.
Thanks
Thanks Veena,
I will try this as well today and Let both of you and Debasis know the outcome tomorrow....
Thanks Once again
Hiren
Ok I tried it, but what's happening is I am able to save first record of the day, then while saving second record it gives duplicate value error as this no. in the table is a primary key.
I managed to save 1 record yesterday 140208-001 and 1 record today 150208-001, but I am not able to save second record in the same day.
Here is my code
======== My Code (VB) ===========
Dim NextNum As String
Dim TNo As Integer
Dim RST As New ADODB.Recordset
Dim sSQL As String
NextNum = Format(Date, "ddmmyy")
sSQL = "Select Max(TestNo) From Test Where TestNo Like '" _
& NextNum & "*'"
RST.Open sSQL, Con, adOpenStatic, adLockOptimistic
If Not RST.EOF Then
RST.MoveFirst
sSQL = Trim(RST(0) & "")
If Trim(sSQL) <> "" Then
TNo = Val(Right(sSQL, 3))
End If
RST.Close
End If
TNo = TNo + 1
NextNum = NextNum & "-" & Format(TNo, "000")
======== Code Ends ============= I am getting Following Error:
"The Changes You requested to the table were not successful because they would create duplicate values in the index, Primary key or relationship....."
QVeen72 1,445
Recognized Expert Top Contributor
Hi,
Keep a BreakPoint and check at the end of the above Code what is the value of variable "NextNum "....? and "TNo" ...?
also check what is RST(0)...
What is your Backend Database...?
If SQLServer or Oracle , Replace * With % in SQL Statement..
Regards
Veena
TNO = 1
NextNum = "-001"
its not increasing TNO
QVeen72 1,445
Recognized Expert Top Contributor
Hi,
Keep a Break point and check from the beginnig.. What Database?
REgards
Veena
Database is MS Access 2003... Whats happening is, For Every record of the same day it doesnt pass No.2, TNO is always 1 and thats why its giving problem.
I tried through Break Point using stop command.
It doesnt increment TNO.... Always Makes TNO 0+1 = 1
Regards
Hiren
QVeen72 1,445
Recognized Expert Top Contributor
Hi,
VB6 or VBA...?
My Code is for VB6.. not sure it will work for VBA or not..
what is RST(0)..?
REgards
Veena
I am using VB 6 as well...
There is something very small we are missing out.... I have tried all possibilities...
if you are on Yahoo or MSN, Can you please add me on your messanger so that it will be faster for us to communicate... My ID ismail id removedin both.
Regards
Hiren
Veena,
I have mailed u the code and table please check your mail
Hiren
Veena,
I have mailed u the code and table please check your mail
Hiren
Now you check your PM.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Laphan |
last post by:
Hi All
This is a strange request, but I just cannot fathom how to do it.
In theory the requirement is very basic, but in practise its a noodle!!
I have 10 team names like so:
Team A
Team...
|
by: Sebastien |
last post by:
Hi,
I am building a products database, linking sales and production. Each
part has a unique sales Stock Code and Production Number.
The sales stock code is a combination of letters and numbers...
|
by: SalimShahzad |
last post by:
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...
|
by: Bill Rust |
last post by:
I've created an "Add Item" wizard for VB.NET 2003 that allows a user to add a
specialized class that works with my application framework. In the wizard,
the user can select the interfaces they...
|
by: gwhite1 |
last post by:
I am using the auto-generate fields option because my query can be
different based on what the user selects. But I would still like to set
the column alignment but I can;t seem to access the...
| |
by: G |
last post by:
Hello Firends
I want a sample code for developing an " auto genearte number " and want to
store in database.
Please if you find any code please send
Thanks in Advance
G
|
by: ganesh22 |
last post by:
hi...
I am doing a project asp.net with C#.my requirement I want to do auto generate password for my application that means when user forget his password when he clicks a link it will auto...
|
by: DanielLauJJ |
last post by:
When inserting a record into a table, I want SQL Server to generate a
number automatically for the Primary Key. (e.g. OrderID is 1, 2, 3
and so on) How to do it?
(This behavior is similar to the...
|
by: Jagdish Patil |
last post by:
I have project in asp.net with sql server backend.
i want to auto generate a number for particular column.
with the auto generated number i want to insert some other data in the same row same...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |