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
Related
I have a form that shows the records from Table-A, it is a continuous form. I have a textbox that uses a DCount expression to count records from Table-B that share the same SOP-Number.
=DCount("*","[Table-B]","SOP = " & [SOP])
This works but I don't know how I would go about sorting that column based of the resulting values. The other columns are sorted thus:
" ORDER BY [FIELD NAME] ASC;"
So without a field I don't know how (or if) I can sort the form.
Could I create a RecordSet to store the values then sort by that field (I don't know if this is even possible)
Thank you
Dan
Access 2016 (365)
I'm not quite understanding why you won't know what fields you're pulling from Table B. But you can always order by the column number. So if you're looking to order by the first column, just put:
ORDER BY 1 ASC
You can't sort the recordsource but you can sort the form itself:
Me.OrderBy = "NumTasks DESC"
Me.OrderByOn = True
(assuming your textbox with the DCount control source is named NumTasks ).
You could change the datasource to
select ,DCount('''[Table-B],'SOP=' & SOP) from [Table-A]
order by DCount('*''[Table-B],'SOP=' & SOP)
This is not a good soulution i Table-A is big.
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 & ");"
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.
I have a table named "customers", and a table named "cases". These relate to real estate transactions. On the table "cases" I have a field for "other party", which lets you enter a new customer or pick from an existing one if we have already had that person in our database from a different transaction.
I have created a form with a listbox so I can search all the case records via the customer and other party fields (I also show some other info about the case but am not needing to search that info). In formview the listbox shows the customer name, but only shows the ID number for the other party. When I go to the rowsource, buildevent, and see the query in datasheet view, the records display the way I want them to -by name, not showing ID numbers.
Why won't it display correctly on the listbox??? Please help! I have spent way to many hours trying to figure this out :( This is my first time using access and I am just figuring it out as I go.
this is the SQL from the query in the listbox rowsource:
SELECT Query3.Customers.ID, Query3.[Last Name], Query3.[First Name], Query3.[Other Party], Query3.[Property Address], Query3.[Assigned To], Query3.Lawyer FROM Query3;
and this is the SQL from Query3:
PARAMETERS [ [forms]]![FRM_SearchMulti]![SrchText] Text ( 255 );
SELECT CasesALL.*
FROM CasesALL
WHERE (((CasesALL.[Last Name]) Like "*" & [forms]![FRM_SearchMulti]![SrchText] & "*")) OR (((CasesALL.[First Name]) Like "*" & [forms]![FRM_SearchMulti]![SrchText] & "*")) OR (((CasesALL.[Other Party]) Like "*" & [forms]![FRM_SearchMulti]![SrchText] & "*"));
Listboxes and combo boxes have a hidden column feature, usually a primary/foreign key of underlying table. Users generally do not know which primary key they should pick, hence the connecting name/item displays for their selection. Your situation sounds like the key is not being hidden but displaying and with two columns designated, you do not see the Other Party field.
To fix, under Property Sheet / Format Tab of the listbox, adjust Column Count and corresponding Column Widths according to your query (i.e., recordsource of listbox). As shown below the first column of query is hidden with 0 inches of display while the next two fields will display at 2 inches:
Column Count: 3
Column Widths: 0"; 2"; 2"
...
List Width: 4"
Be sure column widths add up to your List Width or there will be cut-offs. Also, inches are automatically added when you enter numbers. Finally, do note the data value of the listbox will be whatever is designated in Bound Column under Property Sheet / Data tab:
Bound Column: 1
Usually, the bound column is the hidden field or it wouldn't be hidden or used!
You probably miss to set columnwidth(s) of the listbox to: 0
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.