Hi Everyone,
I know this topic has been posted a lot, so I apologize for having to post another one, but the answers I've been finding seem to be more advanced than I know how to use.
I have a table called [MOC Tracking Log], with a field named [MOC ID Number]. The general format for this number is supposed to be (yyyy-0001). The last 4 digits are supposed to increment each time a new record is created (ie, 2007-0002, 2007-0003 etc). I have found some useful code (i think) to do the incrementation part itself. However:
1) I don't know how to set the original format to be (yyyy-0001)
2) I don't know where to put the code.
So far, I have this: -
Private Sub Form_Load()
-
-
Format (Date = "yyyy")
-
-
-
Dim tdf As TableDef
-
Dim fld As Field
-
Dim num As Double
-
-
num = "0001"
-
-
Set tdf = CurrentDb.TableDefs("[MOC Tracking Log]")
-
Set fld = tdf.Fields("[MOC ID Number]")
-
-
fld.Value = (Date & "-" & num)
-
-
fld = ("SELECT Max(Right([MOC ID Number])) As MaxNum FROM [MOC Tracking Log]")
-
-
num = fld!MaxNum + 1
-
-
End Sub
-
which is basically a random jumble of code snippets I've found and can only somewhat make sense of.
Any clarification, or links to understandable tutorial sites would be greatly appreciated.
Thanks,
Tiffany
5 3432
Hi Everyone,
I know this topic has been posted a lot, so I apologize for having to post another one, but the answers I've been finding seem to be more advanced than I know how to use.
I have a table called [MOC Tracking Log], with a field named [MOC ID Number]. The general format for this number is supposed to be (yyyy-0001). The last 4 digits are supposed to increment each time a new record is created (ie, 2007-0002, 2007-0003 etc). I have found some useful code (i think) to do the incrementation part itself. However:
1) I don't know how to set the original format to be (yyyy-0001)
2) I don't know where to put the code.
So far, I have this: -
Private Sub Form_Load()
-
-
Format (Date = "yyyy")
-
-
-
Dim tdf As TableDef
-
Dim fld As Field
-
Dim num As Double
-
-
num = "0001"
-
-
Set tdf = CurrentDb.TableDefs("[MOC Tracking Log]")
-
Set fld = tdf.Fields("[MOC ID Number]")
-
-
fld.Value = (Date & "-" & num)
-
-
fld = ("SELECT Max(Right([MOC ID Number])) As MaxNum FROM [MOC Tracking Log]")
-
-
num = fld!MaxNum + 1
-
-
End Sub
-
which is basically a random jumble of code snippets I've found and can only somewhat make sense of.
Any clarification, or links to understandable tutorial sites would be greatly appreciated.
Thanks,
Tiffany
Form load initially, then you would want this each time you started a new record. -
dim MyCount as long
-
if dcount("*","[MOC Tracking Log]")=0 then
-
me.[MOC ID Number].value = Format(Date(),"yyyy") & "-0001"
-
else
-
MyCount = myval = Right(DMax("[MOC ID Number]", "[MOC Tracking Log]"), 4)
-
me.[MOC ID Number].value = Format(Date(),"yyyy") & mycount
-
end if
-
-
J
Hi Everyone,
I know this topic has been posted a lot, so I apologize for having to post another one, but the answers I've been finding seem to be more advanced than I know how to use.
I have a table called [MOC Tracking Log], with a field named [MOC ID Number]. The general format for this number is supposed to be (yyyy-0001). The last 4 digits are supposed to increment each time a new record is created (ie, 2007-0002, 2007-0003 etc). I have found some useful code (i think) to do the incrementation part itself. However:
1) I don't know how to set the original format to be (yyyy-0001)
2) I don't know where to put the code.
So far, I have this: -
Private Sub Form_Load()
-
-
Format (Date = "yyyy")
-
-
-
Dim tdf As TableDef
-
Dim fld As Field
-
Dim num As Double
-
-
num = "0001"
-
-
Set tdf = CurrentDb.TableDefs("[MOC Tracking Log]")
-
Set fld = tdf.Fields("[MOC ID Number]")
-
-
fld.Value = (Date & "-" & num)
-
-
fld = ("SELECT Max(Right([MOC ID Number])) As MaxNum FROM [MOC Tracking Log]")
-
-
num = fld!MaxNum + 1
-
-
End Sub
-
which is basically a random jumble of code snippets I've found and can only somewhat make sense of.
Any clarification, or links to understandable tutorial sites would be greatly appreciated.
Thanks,
Tiffany
Change this: - fld.Value = (Date & "-" & num)
-
to this - fld.Value = (Format(Date, "yyyy") & "-" & num)
-
-
dim MyCount as long
-
if dcount("*","[MOC Tracking Log]")=0 then
-
me.[MOC ID Number].value = Format(Date(),"yyyy") & "-0001"
-
else
-
MyCount = myval = Right(DMax("[MOC ID Number]", "[MOC Tracking Log]"), 4)
-
me.[MOC ID Number].value = Format(Date(),"yyyy") & mycount
-
end if
-
Thanks for the help, it seems to be working so far, with the exception of a minor compiler issue. Could you also tell me what the proper format is to replace "Me." for a table and field?
Thanks,
Tiffany
Thanks for the help, it seems to be working so far, with the exception of a minor compiler issue. Could you also tell me what the proper format is to replace "Me." for a table and field?
Thanks,
Tiffany
Hey,
replacing as in putting a variable in place of??
forms(sForm).form(sField).value for a simple form. Subforms are different.
Ok thanks, I'll try that
Tiffany
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Amy |
last post by:
I'm trying to add an autoincrementing id to a table based on an
existing field Name, but Name has duplicated records. How can I do
that in ACCESS?
Thanks.
Amy
|
by: HD |
last post by:
Hello. For the following, I would appreciate if anyone could tell me:
if it can be done, how it might done, and/or what search terms I could
use to find the solution myself.
I would like to...
|
by: Megan |
last post by:
Hi everybody-
I have 2 tables, Hearings and Rulings. Both have primary keys called,
CaseID, that are autonumbers. I don't want both tables to have the
same autonumber. For example, if Hearings...
|
by: ben.werdmuller |
last post by:
Hi,
Is there an easy way in ASP/VBscript to grab an autonumber (primary
key) field just after an SQL insert? This is probably easy, but I'm
stuck ..
Cheers.
|
by: gtwannabe |
last post by:
I'm having a problem with a form that uses AutoNumber as the primary
key. I have an Abort button to delete the current record and close the
form. If AutoNumber is assigned, the code executes a...
|
by: dympna |
last post by:
HI I am trying to create a number field that will create a unique
incremented number each time a record is added to the database via a
form. but I want that number to be in sequence and start from...
|
by: Tom_F |
last post by:
To comp.databases.ms-access --
I just discovered, to my more than mild dismay, that some tables in my
Microsoft Access 2003 database have duplicate numbers in the
"AutoNumber" field. (Field...
|
by: asandiego |
last post by:
Hey guys, this is my first post here but have been checking this site a lot for anything I need.
I hope someone can lead me to what I should do or just an idea to what can be done.
What I'm...
|
by: bkberg05 |
last post by:
Hi - I have a field called Sequence on a continuous subform. The Sequence field belongs to a table called Project_Draw. This table has many 'Draw' records for each 'Project' record. So then the...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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: 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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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?
| |