Calculated textbox to dynamic table record - ms-access

I am trying to get a calculated textbox' value to copy to a table with a Date()-mark.
I have several textboxes, with similar code to count in queries (This is "Text39" textbox):
=DCount("*";"[QRY_ALLE_faktura&kreditnota_forfald]")
This is counting all open invoices of today and returning ex. "550" as value.
I want to have a button to copy all the values from the 5 textboxes to a table into the specific columns.
Each time the button is clicked, it should timestamp it with Date() (Dynamic rows?)
I've read all questions about the topic in here, none which seem to fit my problem. I've also spend a few full days of googling this, but have come out with no results.
How do i get the value from Text39 textbox copied to Table "Test", column "Depot" while it already made the new row and in column "Date" inserted today's date

In the OnClick event of the button, run code similar to this:
Dim SQL As String
SQL = "Insert Into Test ([TimeStamp], [Depot], [NextField], [AnotherField]) Values (Date()," & Me!Text39.Value & "," & Me!Text40.Value & "," & Me!Text41.Value & ")"
CurrentDb.Execute SQL
But, do yourself a favour an rename the textboxes to something meaningful like txtDepot.

Related

Linking a query criteria to a value in a local table

I have a 5 column table with thousands of rows that I need to be able to filter. In the form where the table is displayed, Form1, I have a text field, Value1, where the table will only display the rows where Column 0 = Value1. If Value1 is blank, all rows will be displayed.
The code below is what is being currently used in the criteria and or field of my query builder and works great:
Like [Forms]![Form1]![Value1] & "*"
IsNull([Forms]![Form1]![Value1])
My goal is to have the criteria grab the value from a table, rather than a form. I created a form that pops up before Form1 that allows you to insert Value1 then hit Search. The value then goes into [Table1]![Value1] then opens Form1 and displays the filtered results. I am successfully inputting Value1 into Table1 but can't seems to get the query to react to [Table1]![Vale1]. I have tried a few different codes, the code below is an example of one:
Like [Tables]![Table1]![Value1] & "*"
IsNull([Tables]![Table1]![Value1])
Any suggestions?
You could use the DLookup function to get the value from the table, like this:
Dlookup("Value1","Table1")
This will work fine if you have only one value in the table. If you have multiple values in the table and need to have a specific value, you need to add a filter in the third parameter of the Dlookup function.
Dlookup("Value1","Table1","TableFieldName=" & [Value])
or, if the criteria value is a string
Dlookup("Value1","Table1","TableFieldName='" & [Value] & "'")
or, if the criteria value is a date
Dlookup("Value1","Table1","TableFieldName=#" & [Value] & "#")
See the docs also at : https://learn.microsoft.com/en-us/office/vba/api/access.application.dlookup

How to use the DLookUp function and if it is the correct function for this job?

I have two tables in my database, and a form that is opened when the user logs in.
A text box in this form will display that users name e.g. "Ollie", I want another text box to display this users contracted hours from within the users table when the form is opened.
I have tried using the DLookUp form in the before update section however nothing happens? Below is an example of what I have tried.
=DLookUp("[ContractedHours]","tblUser","[Operator] =[tblUser]![UserLogin]")
So saying that the value in my form text box "Operator" is Ollie, the value in my table column "UserLogin" is Ollie, i'd like another text box on the form to display the contracted hours on the record for Ollie.
tblUser contains these columns
ID UserLogin Contracted Hours Password
1 Ollie 8:00 *****
2 Ryan 5:00 *****
My form contains a text box that will equal either Ollie or Ryan, and I would like another text box that displays the relevant Contracted Hours.
DLookup will only work if you provide it a valid condition that allows it to identify a specific record in the table. What you have provided is not a value; it's a reference to a column in a table. There's no way for DLookup to know which record you are referring to.
Have a look at this page for some working examples. Notice they all have a condition that points to a specific record:
DLookup("UnitPrice * Quantity", "Order Details", "OrderID = 10248")
or
DLookup("CustomerID", "Orders", "OrderID = Forms![Orders]!OrderID")
It should read like:
=DLookUp("[ContractedHours]","tblUser","[UserLogin] = '" & Me!TextboxWithUserName & "'")
Based on your excerpt from table users, it's probably because you didn't include the space in the Contracted Hours column name in your DLookUp. Also, I would put your form call outside of the string.
Try:
=DLookUp("[Contracted Hours]","tblUser","[Operator] = '" & Forms![tblUser]![UserLogin] & "'")

MS Access convert short time in form to decimal time in table

I have an Access database with a form that contains a "ProcessTime" field, with the format hh:nn and the input mask 00:00. I've got that part working fine. In the Control Source on the associated table, however, I would like the ProcessTime field/column to appear as decimal minutes. I haven't been able to figure out how to do that.
For example, a user might enter a ProcessTime in the form as 01:30, meaning 1 hour and 30 minutes. I would like the associated value in the table to then appear as 1.5, meaning 1 and a half hours.
How can I go about modifying the ProcessTime field in the table to show the time in decimal hours? I had assumed there would be some simple "decimal time" format I could enter for the ProcessTime field in Design View, but I haven't found one yet.
I'm using MS Access 2013.
There is no intrinsic format or conversion function for this. Don't modify the field. Do a calculation in query or textbox.
[ProcessTime] is a date/time type? The following expression will work for date/time or text type.
Hour([ProcessTime]) + Minute([ProcessTime])/60
If the textbox is bound to the field, it will be problematic to make a conversion like that as you will have different data types (date/time and decimal). If it is not a bound textbox you can split the textbox value on the colon (:) and then concatenate hours & (minutes/60) and then write the information to the table.
Dim temp as string
temp = split(ProcessTime.Value,":")
currentDB.Execute "Update <table name> SET ProcessTime=" & temp(0) & temp(1)/60 & "WHERE <condition>;"
'Or you are adding a new record you can do an Insert Query
' Replace the Update statement above with "INSERT INTO <table name> (<other fields>,ProcessTime) VALUES (<other values>," & temp(0) & temp(1)/60 & ");"

Filtering A Lookup Field Based On Another Field

I have a lookup field in my table based on another table. I'm having trouble filtering those values based on another field that is entered prior to the field.
Is it possible to filter a lookup field based on another field?
EDIT
Let me try and clarify my original question, sorry about that. Ok, so I have a table1 that has the following fields: ID, Name, Logo.
If a user enters a specific name in the Name field, when they click on the Logo field, it'll only display those values associated that are similar to the name entered. Does that make any sense? If it does make sense, would there be an easier suggesion on accomplishing this task?
If you're talking about inside a table, the answer is "No". You can create cascading combo boxes on a form, but you can't base a lookup value in a field of a table off of a different field in that table (or the field in any other table).
Here is an example of how to handle filtering a combo box based on the value selected in another combo box:
I have the following form:
The combo boxes are named cboIntPN and cboManPN.
The Row Source for cboIntPN is set to: SELECT uniq_key, part_no, revision FROM inventor. The Row Source for cboManPN isn't set to anything.
When the user selects a value for Internal PN the following AfterUpdate Event is triggered:
Private Sub cboInternalPN_AfterUpdate()
[cboManPN].RowSourceType = "Table/Query"
[cboManPN].RowSource = "SELECT uniqmfgrhd, mfgr_pt_no FROM invtmfhd " & _
"WHERE uniq_key = '" & cboIntPN.value & "'"
End Sub
It sounds like he is having the same issue as me. I also wanted to filter a field in a table for data entry on another field's input and my conclusion is "it is time I stopped entering data manually in tables and begin to create Data entry forms. I was putting this task off until later, but if I don't do it now, I might make worse trouble for myself later.
Btw, what an old thread.

How to update a coloumn in access 2007 based on a calculation?

Basically i have a table with one coloumn "stock" and second coloumn "stockissued". supposing
stock coloumn has value 40 this means there are 40 items in the store and i want that whenever we type value for stockissued coloumn the previous value of stock is decremented accordingly. Like if out of 40 we write 10 in stock issued field in a form the stock value should decrement from 40 to 30.
Another important thing is that new record in a form for stock field should have the previous decremented value updated everytime.
I need urgent help bcz working on a project!
As you have stated that you are entering the value onto a form, this is actually very easy. You could use the following code on a button click or set it to run when you update the field you typed the value into.
I am working from the assumption that you have the current value and the amount to decrease on the same form.
Dim UpdatedValue as string
UpdatedValue = Me.stock - Me.stockissued
Updatesql = " UPDATE YourTable SET YourTable.Stock=" & (UpdatedValue) & " " & _
"WHERE [YourTable]![RecordID] = Me.RecordID "
Docmd.runsql updatesql
Obviously you need to replace the table and field names with your own, also I added in a WHERE criteria that should ensure you dont accidentally update all the records in your table! just the one active on your current form