I am using Access 2010 to create a database of fish caught by local fishermen. I have a table with all the information about each fish caught (location, day, length, etc) and a form to add new records to that table. I am trying to automate as much of the data entry as possible because we have many interns that will be entering data throughout the summer. The more I can have the program do, the more I can limit mistakes in data entry.
I would like to store the length data in metric (mm), however most of the fishermen report the lengths of the fish they catch in inches. I don't care to have length twice in my database, one metric and one imperial.
Is there a way I can have a box on the form that someone can enter the length in inches and this value is converted to metric and used to fill in the length field on the table? The trick is that sometimes the fish length is reported in metric, so I need to be able to directly input metric into the form too.
I'm guessing this is either not possible or already somewhere & I am not using the right key words in my searches. I appreciate anyone who can point me in the right direction.
Thanks!
Here's one way to do it. It's similar to Scotch's, but with a few enhancements.
Have 2 textboxes. 1 each for millimeter & inch sizes.
The Milimeters textbox is bound to the table through the Control Source, so what is entered in there is what is saved in the database.
The Inches textbox is unbound. But what is entered into that textbox is converted and the new value is put into the Millimeter textbox. The code would look like this:
Private Sub txtSizeIn_AfterUpdate()
Me.txtSizeMM = Me.txtSizeIn * 25.4
End Sub
This way, the fisherman will have a choice on what measurement to use.
In the After Update for your control in which the measurement is entered, say the control is called Length.
You can change it in vba with this code.
Me.length = me.length * 25.4
This is one of many ways to do this
Related
I'm working on an Access 2007 database and I'm having a problem with a query.
I have a table named Vehicles, which contains data such as ID, license plate and fuel type for each vehicle in it.
I'm trying to make a query which will populate a combobox in a Form with each vehicle's fuel type, based on the license plate chosen by the user beforehand.
The thing is, we have some some cars that work with two types of fuel and I cant' find a way to display them separately in the combobox.
So far it kinda works, code follows:
CheckDiesel: IIf([Diesel]="Yes";"Diesel";IIf([Gasoline] AND [Ethanol]="Yes";"Gasoline"+ "Ethanol";IIf([Ethanol]="Yes";"Ethanol";IIf([Gasoline]="Yes";"Gasoline";""))))
If you look at the second IIf, I have a condition for a bi-fuel car. I want to display Gasoline and Ethanol separately, each one in a row.
I've tried using "&Chr(10) Chr(13)&" and "\r\n" but I had no success so far.
Can anyone help me?
Storing multiple pieces of data in a single field rarely ends well. A few options I see
A series of binary fields for gasoline type. So you'd have a True/false for gasoline, ethanol, and diesel. This is easy to show with checkboxes on the form.
If you know there will only be certain combinations, like if there will not be a 'diesel and ethanol' without gasoline, you can build it as a single value combobox.
You will probably need some VBA to do what you need to do. Try something like this:
Dim R as String
R=""
if (Me.Diesel) then R = R & "Diesel;"
if (Me.Gasoline) then R = R & "Gasoline;"
… {add any other types of fuel}
Me.MyComboBox.Rowsource = R
Me.MyComboBox.Requery
This can be added tot he form's OnCurrent event so it will update the combo box every time a new record is displayed.
If your form does not include the various fuel types as fields, either add them as hidden fields or use DLookup to read them off the table.
I have VBA code that I run from MS Access. This code creates tables (of different sizes depending on the size of a query) in a Word document, and thereafter fills that Word document, with values from a query's columns using the Range.Text property. One of these columns is a currency value and another a percentage value. These values display correctly in Access itself.
Unfortunately values are outputted as eg. 987.6 and 1234.5, instead of 987.60 and 1234.50. As small as this is, it is a requirement and was hoping to find a solution and I am entirely unsure how to do this or if its even possible.
Discounts are displayed as 0.18 or 0.30 instead of 18 and 30
I can show my code for the export of the data if required however didn't see how it affected this part that I require.
That is the answer:
Format(123123, "Currency")
The currency would be from your local settings.
Edit: See the screenshot - open the immediate window, there you may write
?Format(123123, "Currency") and you will see the result. Screenshot attached.
I have a field with a customer ID that should be in the format of C0000000001, where it has a letter at the start and up to 10 numbers after the letter with leading zeros between the letter and the number. I want the users to be able to put in C1 and have the table save C0000000001 or C1234 and have the table save C0000001234.
I want the restriction to be on the hard data in the table. The table should contain the full customer ID but I only want the users to have to enter the C and the number of the customer when entering/searching for customers. I am using Access 2010.
I believe that the first character will always be a C, but either way, it would only be one alpha character if it wasn't.
I understand what you are saying, but the majority of the data (thousands of records) are going to be from another system that stores them that way. Doing it this way limits my margin of error. Otherwise, exports from the other system will need to be manually changed prior to being imported into the database and vice versa.
Searching would only be on existing records that will be saved in the C0000001234 format, but I would like user to be able to omit the leading zeros when entering the search criteria.
This question, combined with your previous question here, suggest to me that you are trying very hard to have the data structure in your Access database exactly match the legacy system from which you receive bulk updates. That may not be necessary, or even desirable.
For example, instead of maintaining the CustomerId as Text(11) (as in the old system) you could store it in your Access database as
CustomerIdPrefix: Text(1), and
CustomerIdNumber: Long Integer or perhaps Decimal if the numeric part really can exceed 2,147,483,647
Your Customers table in Access could also include a calculated field named CustomerId as
[CustomerIdPrefix] & Right("0000000000" & [CustomerIdNumber], 10)
to give you a single 'C0000012345' value for display purposes.
For searching, your form could have a Text Box for the Prefix (default value: 'C') and another text box for the numeric part. The search could then use a condition like
[CustomerIdPrefix] = txtPrefix.Value AND [CustomerIdNumber] = txtNumber.Value
or, if the user wanted to create a Filter on the Form (or Datasheet View) it would probably be sufficient to just filter on the number part.
If you ever needed to feed information back to the legacy system you could just export a query that includes the [CustomerId] calculated field (and omits [CustomerIdPrefix] and [CustomerIdNumber]) and you'd be fine.
My suggestion would be to use forms with associated queries using the FORMAT function.
You do need to clarify where you want this implemented, but I'm going to assume you have a table set up and that you would like to be able to enter/search data from a form.
I'll create one form for input frmAdd. For the input form, I created a query that would run when a button on the form was pressed. Add two text boxes newID and newOther to the forms which are unbounded but which the user can use to enter data. The query will then pull that data and append it to your table in an altered format. Here's the SQL for that query:
INSERT INTO Customers ( [Customer ID], [Other Field] )
SELECT Left([Forms]![frmAdd]![newID].[value],1)
& Format(Right([Forms]![frmAdd]![newID].[value],Len([Forms]![frmAdd]![newID].[value])-1),"0000000000")
AS Expr1, Forms![frmAdd]!newOther AS Expr2
FROM Customers;
I'm not sure exactly what search functionality you're looking for, but this query would pull up the record data matching that of a frmSearch with a textbox search which would have the format C### or whatever entered in:
SELECT Left([Customers].[Customer ID],1) & Replace(LTrim(Replace(Right([Customers].[Customer ID],9),'0',' ')),' ','0')
AS Expr1, Customers.[Other Field]
FROM Customers
WHERE (((Customers.[Customer ID])=Left([Forms]![frmSearch]![search].[value],1)
& Format(Right([Forms]![frmSearch]![search].[value],Len([Forms]![frmSearch]![search].[value])-1),"0000000000")));
Applying the input mask is just a way to ensure that your data is correct. If you feel the need to use one, go to the table in Design View and click on the Data Type box for the customer ID field. Find Input Mask under Field Properties -> General and click it. Then hit go to the toolbar -> Design tab -> Builder. This will walk you through it.
Input mask is not the answer for this. Input mask forces the user to input the data in a certain manner. What you need is some VBA code to run in the AfterUpdate event on a form. There's no way within the table to force the data into this pattern allowing the input method that you've requested.
There may be a more efficient way to do this, but this does the job.
http://pineboxsolutions.com/access/customeriddemo.accdb
This is specifically for MS-Access Web Databases (requires Sharepoint hosting) which has many limitations compared to their client counterparts, like no VBA, instead you get form macros and data macros to manage data.
I've run into a weird bug on one of my applications. I have a query used to check stock levels against a "minimum stock level" also saved in the table. The query is pretty intense and there are over 4,000 records now to check against. These querys normally take about 75s. So I have made a little label that gets updated every time the form is loaded showing the time and date the query was last run, and the duration in seconds it took. (so users can see how fresh the data is and decide if it needs to be run again)
Now, the weird thing is it works fine in my Access client, but when I sync my changes to the server and try it in a web browser I get a "type mismatch" error. A small table is used to store the start and end times whenever the query is run, that's how I get the timestamp data. These fields are in a "Date/Time" format, obviously. But it seems the problem here is changing the date format to a string format so it can be put in a label on the form. The Access client seems perfectly capable of doing this, while the web client stumbles and falls.
My problem is, how do I change data in a date/time format to a string format in a Web database? I can't figure out how to do this. The tools are so limited. I may have to end up answering my own question here but I'm posting this for others just in case.
To return a value from a data macro as string, you have to format the internal date/time format as a string. In Access an internal date/time value is a double number with the integer part as number of days since 1900, and the “decimal” time part is a fraction of 24 hours. Unfortunately if you simply wrap the date/time in the str$() function we had for 20+ years, then you get something JUST like if you type this into the debug window:
? cdbl(now())
41955.5478587963
The solution is to simply pull out each part. And “nice” is while in few cases a data macro will cast the data type, it does in this case and thus the STR$() command is not required.
The expression you thus can use is this:
Month([d]) & "/" & Day([d]) & " Time = " & Hour([d]) & ":" & Minute([d])
So say to pluck out the VERY LAST start time column from say a invoice table, since we don’t have a dmax(), then we simply sort the table in the order we want and pull out the first row.
Our data macro will thus look like:
Note how in above I simply typed in the SQL and SET the order on the date/time column. I want the MOST recent invoice start date and time. For those new to SQL, then I suggest you build a query in the query builder and specify a query in above lookup feature, since many are not "comfortable" typing in free hand SQL as I did above.
Now, in your browser side (UI) macro, you can use this code:
The above returns a formatted string that you can stuff into a text box, or as per above code change the caption of a label.
Unfortunately with silly problems like this, it becomes a path-of-least resistance thing.
Since my intended result was simply to get "a timedatestamp from a table to show up on a form (so users could see when a query was last run)", this became redesigning my form in Access to be a text field instead of a label. Text fields can be adjusted to accept "Time/Date" formats, so this is exactly what I did, it now pulls the timestamp data directly from the last record of the table and requires no extra formatting to appear in the web browser. I redesigned the text field to appear and function more like a label, and my desired function was achieved.
However, since my question specifically asks, "how do you change a time/date format into a string format in a Web db?", I will leave it here in case someone actually does solve it.
Please help with me a conceptual problem I've been trying to figure out for the past 3 days now. I'm trying to use Access to centralize the tracking of training that was previously done on separate excel spreadsheets. I have about ~340 employees that are categorized into 12 different positions all with varying degrees of required training. I have an example below:
Position 1: Class A, Class B, Class C
Position 2: Class A, Class B
Position 3: Class A
Position 4: Class A
As you can see, all 340 personnel require the Class A training. But only some positions require the Class B or even Class C. Right now I have a single table with the individuals name and associated contact information and all 12 possible classes. All I want access to do is store the date they've completed training, nothing else. The problem that I'm running into is that the Date/Time field cannot distinguish between someone that is required to take that class and simply hasn't done it yet (a null value) vs. someone that is not required to take the class and obviously hasn't completed it (also a null value).
What I've tried:
-A query using calculated fields that will enter in the value "NOT REQ" if the job position does not require the training. An example is below:
HAZMAT Inspector: IIf([POSITION]="Load Planner",[HAZ Inspector],"NOT REQ")
Why it doesn't work: Inserting text into the field changes it from a date to a text field so I can no longer use Date functions to determine if training is expired. Also, I cannot edit the field on a form and save it back to the original table due to it being a calculated field.
Possible Solution(?): Use a SQL Update statement in VBA to write the value of a calculated field back into the original table? I still run into the problem that I cannot update the field to begin with on the form...
-Separate Tables for each Position(?): The main problem I see with this is that a lot of positions require the same exact class so I'd be entering in a lot of redundant information.
-Separate Tables for each Class (?): I can see how I'd be safer with this route, but for it to be useful I'd imagine I'd have to write some type of VBA code that says when I assign someone to Position X, his Employee ID is automatically populated in Tables A, B, & C based on his position's training requirements. Is that doable? Is this the best option, or am I just off the mark?
As you already explained, you cannot make entries in a calculated field. You will need a different approach. The approach depends if you display only one employee per form (Single Form) or if you display a list of employees (Continuous Form or Datasheet).
On a Single Form I would simply disable the fields which do not apply
me!txtClassBDate.Enabled = me!txtPosition = 2
You can call this code from Form_Current and possibly in the AfterUpdate of a control used to change the position type.
The other possibility is to use conditional formatting. Select the date-TextBox; then open menu "Format" > "Conditional Formatting..." (I do not know where that is on the ribbons of Acc 2007+). Here you can define the appearance of the control depending on the evaluation of an expression. You can also set the control in a disabled state.