Access New ID Field YYYYMMNN [duplicate] - ms-access

I need to automatically generate a 12 character value for my Business Key. Without any user interaction.
8 character -> Today Date (yyyymmdd or ddmmyyyy).
+
4 character -> Sequential Number (0001,0002,0003).
The Sequential Number must reset on each new day.
Is it possible to do this in Microsoft Access 2010+ without any coding involved?

Since you are using Access 2010+ the best way to accomplish your goal would be to use a Before Change data macro like this
To create the Before Change macro, click the "Before Change" button on the "Table" tab of the ribbon when the table is open in Datasheet View:
For more details on Data Macros see
Create a data macro

Good question, thanks for the challenge!
After some search, it seems it's possible to do that.
You can prefix the AutoNuber value by processing like the explanation available here: http://www.databasedev.co.uk/add_prefix.html
You can try to specify in the format of the field a format(now(),"ddmmyyyy").
Check this page for more informations, another user seems to have the same problem and got a solution: http://bytes.com/topic/access/answers/695188-custom-made-autonumber-show-todays-date
Hope it's helping you!

Related

How do I create a Microsoft's Access field within Delphi using code

I am currently working on a Bed and Breakfast management system. I want to create a Microsoft access field in Delphi using code. The field name I want to create is rooms, I want the data type to be text and I want the size to be 6. I found some code on a stack overflow post but not everything. I dont know what to put in the brackets.
//Adds the field to the ms access database
Adotable2.fielddefs.add()
It is quite simple to add a field to an Access table, provided no app has the table open at the time. However, using FieldDefs.Add is not the way to do it, because it does something else which isn't relevant to this task.
Assuming your Delphi form (or datamodule) has an AdoTable1 set up to access the table you want to alter, and that the table's name in the Access database is 'Hotels', this will add the Rooms column to it:
procedure TForm1.Button1Click(Sender: TObject);
begin
if AdoTable1.Active then // close the Hotels table if AdoTable1 accesses it
AdoTable1.Close;
try
AdoConnection1.Connected := True;
AdoConnection1.Execute('alter table Hotels add column rooms text(6)');
finally
AdoTable1.Open;
end;
end;
Note: My AdoConnection1 is set up to access the database using the 'Microsoft Office 16 Access Database Engine OLE DB Provider'.
Btw, if you use "persistent fields" in your AdoTable (the list of fields you get if you right-click on it and select 'Fields Editor ...' from the pop-up menu, you will need to add the Rooms field to it. If you don't use persistent fields, you don't need to worry about this.
The FieldDefs.Add you mentioned is for adding a field in your Delphi app to e.g. AdoTable1 if, for some reason, it did not already include it, for example if you added the field to the table using the MS Access app.

How to specify Microsoft Access auto number prefix value based on user selection

I am currently experimenting with Microsoft Access and was curious how one would accomplish this.
I know that one can add a prefix to an autonumber in the format option such as "EMP"000, and each autonumber would fill as EMP001, EMP002, and so on.
What I would like to do is have the "EMP" change dynamically so if my personnel table has them as a Manager for example, it would be listed as MGR003, MGR004, etc.
My thought was to have something like the following in the format section but again am still new to indepth access so please excuse my crude write up.
"SELECT FROM [PersonnelTable].[PersonnelAbbreviation] if [Add Task].[AddTaskPersonnelType]==[PersonnelTable].[PersonnelType];"000
So to recap, I have two tables one "Add Task" the other "Personnel". Would like prefix on Add Task AutoNumber to be based off the abbreviation I have in table Personnel.
Thank you Stack Overflow users!
Simply use a query (air code)
SELECT anydesiredfields, PersonellTable.PersonellType & Format(PersonellTable.PersonellID, "000") as FormattedID
FROM PersonellTable
INNER JOIN AddTask ON PersonellTable.PersonellID = AddTask.PersonellID

Infopath Linked Fields

Pretty new to Infopath here and I can't seem to google this right so i'm going straight to my last option!
I'm building a form in which a Dropdown list needs to change dependant on the value of another dropdown list
So If X = 1, Then Y = 3 etc.
I'm just not aware of the functionality of Infopath and how I can get something like this working.
Thanks.
What you are looking for can be described at the following post:
Auto-populating an Infopath form after selecting a drop down
Essentially you will be using the rules manager to indicate that when a field equals something it will populate another field with data related to it. Think of it as more complex vlookup. Additionally, the verbage you would want to use to google more on the subject would be along the lines of "infopath auto-populate field based on another fields value".

Default value in data table design

I'm designing a data table in Access. I have two columns whose values are something like:
col1: CU001-
col2: 03
and i want to join these two string to form another column's default value like: CU001-03
How can i do this?
And one more question is whether using a string as main key tends to be much slower than a numeric?
I’m fairly sure (but open to correction) that you cant have this kind of thing in access using the default value however you can get the same effect by doing something like this.
If you have an unbound form then you can set the value of your 3rd column before you save it like this presto code
With rst
!YourCol1=”foo”
!YourCol2=”bar”
!YourCol3= !YourCol1 & !YourCol2
.Update
End with
Search on “unbound forms” on google to see full examples of unbound forms, also if you are only using JET to store your data then use DAO over ADO as it will be faster
EDIT
I have not read any books specifically on access but I can strongly recommend a few access websites that have helped me. Here they are in no particular order
http://www.mvps.org/access/
http://www.granite.ab.ca/access/
http://www.lebans.com/
http://allenbrowne.com/tips.html
There are many more out there but they are a good place to start

MS Access 2003/2007 - Passing data through a variable on unbound forms vs. a hidden text box

Ok so I hope the title of the question matches what I about to ask, but here is what I am trying to get at:
So I have an access database that uses a number of unbound forms, and the purpose of the forms are to collect data and save to various tables with VBA click events using SQL statements (INSERT or UPDATE based on whether the ID of the record is present on the form in a hidden text box). When entering a new record (via INSERT), I get the row number with
MyRow = db.openrecordset("SELECT ##Identity")(0) 'thanks David
So you maybe getting the picture. If I have another form that relates to the first form in terms of the record, I just open a recordset and pass that value to another hidden text box.
So my question is, is there a better way to do this regarding passing that value (or just using that value) using a variable instead of this awkward method. So I realize a lot of folks are going to go with the obvious answer of, "Why not just make your forms bound instead of all this code"...and I am sure that is a valid answer, however I inherited this database which was already put together like this, and re-structuring it would be a daunting task.
Any and all advice, or learning resources are greatly appreciated, as they always are!
I use unbound controls on forms for all these kinds of values. The current solution of using an unbound form is sounder than using global or form level variables. If I recall the details correctly while debugging code and you hit the stop button you lose all global or form level variables. Or if the user hits an unhandled error.
Have you looked at OpenArgs?
DoCmd.OpenForm "Form1", , , , , , "Hello"