80 likes | 202 Views
Database expressions Creating automation in forms. Generating an automatic ID. Expressions. Dmax(“Field name”,”TABLE NAME”)+1 # finds the highest value in field from table addss 1 to it Val([FIELD NAME]) # switches datatype to a value Right([FIELD NAME],2)
E N D
Database expressionsCreating automation in forms Generating an automatic ID
Expressions Dmax(“Field name”,”TABLE NAME”)+1 # finds the highest value in field from table addss 1 to it Val([FIELD NAME]) # switches datatype to a value Right([FIELD NAME],2) # gets 2 characters from the right hand side of the field =DMax("Val(Right([StudentID],4))","TBL_Students")+1
Ucase() # switch to uppercase Lcase() # switch to lowercase &””& # concatenation Left([StudentForename],1)&””&Left([StudentForename],1) # returns first letter first name followed by first letter surname
Generating next ID number • Create a form based on the table that you are creating a new entry for • Any fields that make up part of the ID need to be hidden from the user and an unbound field created in its place that the user can enter the data into • To make the bound forename and surname fields invisible set the visible property to ‘no’, you will also need to do this for the label for these fields • You will also need to make an unbound field that just generates the next number for IDs – this can be hidden from the user • The three unbound fields required for this example are highlighted in red • Make sure all fields are named appropriately so you can refer to them later
Generating next ID number pt 2 • Using the field you created for finding the next ID number create the default value above • DON’T FORGET TO USE YOUR OWN TABLE AND FIELD NAMES!
Generating next ID number pt 3 • Set both of your bound first name and surname fields to get their value from the unbound version • =[UNBOUND FIELD NAME] will automatically fill the field based on what the user enters into the unbound field. • This allows this information to be saved into the table • Do the same for both forename and surname fields
Generating next ID number pt 4 • Set up the default value of the ID field as per the scenario (you may need to work this out by looking at the data) • Concatenate the various parts of fields together using &””& • NOTE: the fields referred to will always be the UNBOUND fields
Generating next ID number pt 5 • Create a macro on the on lost focus property of what ever is the last field the user needs to fill in in order to have all the information necessary for the computer to generate an ID (DO NOT PUT IT ON THE FIRST FIELD, IT WILL NOT WORK!) • The macro will simply requery the form and update the fields with the information as per the expressions used in the default values • You should now have generated an ID • Make sure you read the scenario carefully and study the data so you know what makes up your ID – it will not necessarily be the same as this scenario