Libre Base create field on date and auto increment value - sql

I have inherited an excel spreadsheet of ~7000 jobs that I want to turn into a database. I am trying to write a new job entry form. One of the fields is a job ID that is the (YY) year followed by a three digit sequential number, eg 16001,16002... Clearly this will need to change with the year and for this reason using this as the primary key is unsuitable. It is highly unlikely there will be more than 999 jobs per year.
Could anybody explain how I can get the field in the form and subsequent table entry to update automatically with the next job ID? I can access the last entry value with Tools>SQL>SELECT... statement and even return that value + 1 but cannot figure out how to create a field in my form that can automatically display this value.
Thanks all
Axel

There are good examples (credit: user DACM) on using database forms in the OpenOffice community forum, see: [Example] Invoice Forms (without macros)
Have fun!

Related

Increment a number by 4, starting with a number I choose

Is it possible, if one does not want to take the AutoValue, to take as default value for a Large Integer, or even normal number, the largest value already used for this from the column and add to it?
I need an increment of 4, starting with a number I choose.
I'm using version 2016 of Office.
I found several possible solutions, which I've entered into the expression generator of the default value at Field Properties:
CODE: SELECT ALL
=Max([MyID])+1
Or
CODE: SELECT ALL
=DomMax("MyID"; "Table name")
I always get the error message:
Unknown function 'DMax' in the validity expression or default value in 'MyID.TableName'
I came across the tip that the references under VBA Editor --> Extras --> References must be correct. Here, however, I haven't the slightest idea which of these I would have to activate, if this is the problem at all.
The PrimaryKey of a table can sometimes be used as a part number in a Parts table or a userID in a Users table but otherwise is a number the user of a database should never see and certainly not manipulate. This is the first reason I suggest solution 2.
Solution 1. In Access just like with any other database I have seen that uses SQL, You can create an AutoNumber that increments by 4 using the Data Definition Language part of SQL. Maybe the Access designers considered changing the increment too rare or too advanced to put in the menu system. However, Altering the increment is not hard just open the query designer and go to the sql tab and type in appropriate SQL.
In Access 2007, how do I change the Auto Increment value?
First, Create your table as normal but don't insert any data. Then open the query designer, and open the sql pane (In this case it doesn't matter what you have in the design view as you are over writing any SQL), type
ALTER TABLE MyTableName
ALTER COLUMN MyAutoNumberColumnName AUTOINCREMENT(1,4);
The sql pane's ribbon should auto select Data Definition Language.
Run the query and solution 1 is done. When you enter Data in the table MyAutoNumberColumnName will start at 1 and increment by 4.
Solution 2: Don't use the primary key. Instead create another variable and display it. This is one example why data should be entered using forms. In the form's BeforeInsert Event calculate the variable and set it's textbox.
Private Sub Form_BeforeInsert(Cancel As Integer)
Me.txtBoxAlternateIDColumn.Value = Nz(DMax("MyAlternateIDColumn", "MyTableName") + 4, 1)
End Sub
'NZ handles the annoying case where the table is completely empty
I've used Solution 2 a couple times and I don't let the person doing data entry even see the alternateID textbox on the data entry form.
You can also use a Create Table statement in the DDL
Here is a youtube example of solution 2: https://www.youtube.com/watch?v=ZOg4P6v5ewA

Find most recently edited row in MS Access

In Access VBA, is it possible to find the most recently edited row (Record) in a table?
Example below would be ID 3 as the most recently edited row
Since you are using Access 2010 you can use a Before Change data macro to automatically update a Date/Time field in your table. For example, if you add a Date/Time field named [LastUpdated] then the following macro will update that field whenever a record is inserted or updated:
The advantage of this approach is that it takes place at the table level so the [LastUpdated] field is updated regardless of how the record is inserted or modified. (That is, you don't need to rely on form code to update the field.)
You can add a time stamp field to your table and create a form based on the table. When shown as a table, the form will give you the same functionality as the table itself, but you will be able to set an event AfterUpdate The event can then (over)write the time stamp for that record. You can hide the time stamp control on the form if you like, or set Enabled=False

Insert into datagridview column specific values in vb net

i am developing an app for windows in vb net.
I am stuck in the last part which is the following and i would like some help on to where should i look or do.My question:I have one database in mysql called patient.each patient have the usual columns(name,surname etc..).Apart from all the columns there is one column called 'time' and another one called 'date'.I have also one datagrid where these values are displayed.When a new user is to be added,all the fields are filled and in the 'time' he fills the time of visit.I would like to ask if there is any way to restrict the range of time according to date...for example to be able in the beginning before adding the new patient,to say that in august 30 of 2014 the range of time for appointments is from 9 to 10.So when the new patient is added on that date ,to book only between this range every ten minutes eg 9:10,then 9:20 and so on until 10.
I am really stuck and been searching the last week for a solution ,so any ideas on the implementation would be appreciated.
Thank you in advance..If you need some of my code let me know.
If you want to restrict the input data, you have to use the DataGridView's CellValidating event. There you can check wether the input is ok or not. If it's not ok, you can set the ErrorText field of the edited row, where you can explain to the user what's wrong with his input.
Have a look at this HowTo from the MSDN.

Sorting Fields In access by the time they were entered

What I have here is a table with some text fields. I basically put in the name of some students into a table. I got their info from forms that teachers had sent me. When I put their names into the database, I just put the names in based on which form was at the top. Does access track the actual time that a field was put in in such a way that I could sort my text fields by that so that when I give a list of what I just did to someone else, they won't have to sort through the stack of papers to make sure all of the papers are there?
I should add that I need to track this for an individual field, not just for the record. For instance, let me take this one piece of paper I have. When I get it from an outside agency, I then put it into the database with the student's name and some info. I then need to send it to the teachers for them to sign and send back to me. I am on the second part so the record had already been created, but I want to find the date that I entered the Date_signed field basically.
In this example, you set the default value of the dtmEntered field to Now()
p.s. Same answer as HugoLemos but with a pic :)
You can use a Date/Time field with its default value = Now() to store the time each record is created, as already suggested. That approach works fine when only one user can be adding new records, which sounds like your situation.
If you wish to also store the time an existing record is changed, you can do that from a form's before update event.
This example assumes a text box named txtLast_change which is bound to a Date/Time field in the form's record source. The text box does not have to be visible to the user for this to work.
Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.txtLast_change = Now()
End Sub
Create a field with a date type and set default value to Now()
As you have discovered, there isn't any way after-the-fact to know when data was entered in to your table, as it's not something that you captured in the first place. As you mentioned in one of your comments, you can determine the order in which you entered new records based on the Id, but knowing when additional data was entered would require more tracking fields.
In the future, you may want to think about a table design along these lines:
Column Name Column Description
ID Record Id
STUDENT_ID Student Id Number
STUDENT_FIRST_NAME Student First Name
STUDENT_LAST_NAME Student Last Name
... Other student info ...
DATE_ENTERED Date/Time entered
DATE_SENT Date/Time sent to teacher
DATE_SIGNED Date/Time signed by teacher
UPDATED_DATE Date/Time record last updated
UPDATED_BY User that made the last update
If it's possible, you could always edit your table and add these datestamp columns. You'd have to allow for null values, as the previous entries wouldn't have a date/time value for some of them, but it would let you track future entries.

InfoPath 2010 NaN

I have been trying to update a text field in a form that will automatically generate a new number in a read only state when a user fills out the form. When the user completes the form and selects the submit button, the form will be attached to SharePoint List and the following user will open the form and the number field will be the number +1. I have used 'count(mynumber)' and the field returns 1, but when I close the form and re-open it, the field still displays 1 and never increases. When I use 'count(mynumber) + 1' the field returns 2 and also never updates. Finally, I used 'max(mynumber) +1' and it returns NaN. I have come to the conclusion that there is an array here, but don't know what I need to do, to fix this.
I have informed my manager of 'InfoPath 2010 Cookbook' so hopefully this will help, but I also took a gander as this following link, which was not easy to follow as I believe its for 2007 instead of 2010.
http://claytoncobb.wordpress.com/2009/06/15/auto-numbering-infopath-forms/
I am using SP 2010.
So, here is the simple approach to the simple request:
•Just like in any database, every item in every list and library in SharePoint has a unique ID. This ID is stored in the ID field, which is available for viewing in any list or library. Go to your list, modify the view, and check the box next to the ID field so you can see what I mean. This ID is 100% guaranteed to be unique and is never duplicated.
•Since you already have purchase order numbers, you can't use the IDs by themselves, however, you can use them to drive your auto-generated Service Order numbers
•The easy method for doing this is to utilize your SO field, which is now a Number field, and determine the differential between the next ID in the list and the next Service Order number that needs to be created.
•Then, create a simple workflow in SharePoint Designer 2010 that ONLY runs on the creation of a new item (only runs once per item/form), and set it to add the differential to the current item's ID (Something like Do Calculation: ID + 1200) . Next, use Set Field in Current Item to set your SO field to the variable created by the Do Calculation step
From then on, you will always have a GUARANTEED unique, auto-incremented SO # for each form, and you should make this field read-only inside the form so that users can only view it and not edit it.
--Clayton Cobb