How can i restrict the textbox value to stay same in the access database - vba

My goal is to create an access database form with ordering multiple item at a time. But for this phase my end goal is to find the total cost by multiplying price per unit*quantity. Through my working out i got stucked by the problem of on change event. Basically, whenever i change a the id in the combo box it changes in all the textbox that i programmed.
Here is the scenario:
In this case the price per unit stays 1000 for all of the stock ID, whereas, when i have stock id of 2 i want the price to be 0 and so on.
This is how i programmed the get price per unit value
Private Sub StockIDCombo_Change()
Me.PricePerUnit.Value = Me.StockIDCombo.Column(3)
End Sub
Note that the form is continuous.

Have an additional field in the table to hold the calculation, and bind your textbox to this field.

Is your PricePerUnit control unbound? It should be bounded to some table field as other fields (StockID, Quantity).

Related

Give dynamic value to a Form variable in Apex

Im creating an app in Oracle Apex and I having a problem. I have a report that showns every order made. I can enter new orders by pressing "add order". This is the screen that appears when I press it:
I want that when the user selects the product, it price per unit (stored in the database "products") appears in "Product Price per Unit". Then, when the user selects also the total items, the total price can be calculated as Total Items * Product Price.
How can I do this?
I'd first select product. Create "Set value" dynamic action on it so that it populates the price per unit item.
Create yet another dynamic "Set value" action on the total items item which would calculate price * total items and put the result into total price.
In order for dynamic action to work, don't forget to
set items to submit to item(s) used in query (P12_PRODUCT in your case)
set affected elements to item which will be affected by that dynamic action (price per unit in one case, total price in another)

Calculating the number of like records in an unbound text box on a form. in MS Access 2016

I have an unbound text box [txt_AmendmentOF] on a form to count the total number of Amendments a specific record has in the database. So the user knows which amendment they are on. Just a simple you are on Amendment 3 out of 8. i have this calculation i am using in the Control Source field of the text box [txt_AmendmentOF]:
=IIf(IsNull([txt_Amendment]),0,Count([MIPR_Number]))
there is a Field on my table called [Amendment] its text box on the form is called [txt_Amendment]. I have the calculation return a zero in [txt_AmendmentOF] if [txt_Amendment] is null. I need it to count the record number [MIPR_Number] that are the same and return the total number of Amendments count in the [txt_AmendmentOF] text box. on my table i have private key field called [ID] it is an autonumber format. The problem with the code above is it is counting all the fields that have a [MIPR_Number] and returning the total row count of that. i am not an expert here so any help would be greatly appreciated.
Update to post..
I have also tried this and got an error in the text box
=IIf(IsNull([txt_Amendment]),0,Count([MIPR_Number]=[txt_MIPR_Number]))
Counting by a condition is one of the basic dataabase tasks. To get answers from a db, you have to query the database (and that is done by createing a query).
To count same[MIPR_Number]you have to group the data (a group contains same numbers), then count.
SELECT COUNT(id) as CountOfSameNr, [MIPR_Number] FROM Table GROUP BY [MIPR_Number]
Store this query as e.g CountMIPRNumber.
Now you have two options:
Use a Dlookup to get one value
=IIf(IsNull([txt_Amendment]),0,Dlookup("CountOfSameNr","CountMIPRNumber","[MIPR_Number] = " & [MIPR_Number]))
or add the query to form recordsource (join on [MIPR_Number], "SELECT * FROM TABLE" is forms query)
SELECT CountMIPRNumber.CountOfSameNr, TABLE.* FROM TABLE LEFT JOIN CountMIPRNumber ON TABLE.[MIPR_Number] = CountMIPRNumber.[MIPR_Number]
and reference the count field
=IIf(IsNull([txt_Amendment]),0,[CountOfSameNr])

How can I get accurate totals from a subform when in splitform view, currently each record needs to be selected before the total is correct

I am setting up a system for the reconciliation process of accounts payable. I set up a few tables for inputting the groups of tickets that we get every day to log them before we get in the invoices.
I have a handful of tables that provide information about some of the fields in the tables but the key tables are:
Ticket_Group:
TGID(autonumber)
Ticket_Date
SupplierID(Unique Identifier for Raw Material Provider)
ShipperID(Unique Identifier for Shipping Company of classification)
MaterialID(Unique Identifier for material)
gl_dep(general ledger department)
mat_inv_rec(true/false if material invoice has been received)
freight_inv_rec(true/false if freight invoice has been received)
Ticket:
TID(Autonumber for Each Ticket)
TGID(Links to TGID in Ticket_Group, Many TID to One TGID)
qty(Quantity of Material)
What I want to be able to do is see all of the Records from Ticket_Group that still have their invoices not received. But I also need to see the totals so I can match them correctly. Not exactly the ideal way to do AP reconciliation but it is much better than how we currently do it(pseudo-pivot table with supplier and shipper combinations along one side and days of the month along the top and individual tickets as values being added together in each cell).
What I have now is a splitform of the Ticket_Group table with the Ticket subform. I put a sum([qty]) in the footer of the subform and referenced that field in the mainform. This only half works because the total is right in the single form view but the datasheet view displays the selected records total as the total for all records until each individual record has been selected.
I thought maybe an onload event for the form that cycled through every record might work, but I figured there must be a better way.
I am super new with MS Access so I really appreciate the help!
Referring to the Subform-Field can't work because it refers to the actual (selected) record of the mainform.
That's why the Datasheet-View shows the value of the actual selected record of mainform for all records, because there is only one subform with the caclulated field that changes depending on the mainforms record, not a new one for every record of the mainform.
To get the value in the Datasheet-View get it from the tables, not the subform.
E.g. set the Control-Sourceof a TextBpx to:
=DSum("qty","Ticket","TGID = " & Ticket_Group.TGID)
or add the expression to yourForm.RecordSourceas a field like:
Select Ticket_Group.TGID, Ticket_Group.Ticket_Date, ... , DSum("qty","Ticket","TGID = " & Ticket_Group.TGID) as SumQty FROM Ticket_Group
to have the form editable.
Or join
Select TGID, Sum(qty) As SumTicketQty FROM Ticket Group By TGID
with your mainform's query and then bind it to the mainform, but that leads to a readonly query.

vb if condition on items and price from database

I actually have a Access database where i have a table called "tblfreight" and two column is there (items and Price)
And I want to auto show the Price when I choose Items.
There is two Textbox: "txtitems" and "txtprice"
I want to be like this....
If txtitems.text = select from tblfreight and column items Then
txtprice.text = select from tblfreight and column Price
Else txtprice.text=0 (Zero)
You need to query your DB first..
Select * from tblfreight - will get you your data you need.
Then you need to put this data somewhere. You can use a combobox for this. Once you have your combobox filled with your data you then can set the price into a label or textbox easily.
You can use the combobox selected index changed event...
Inside the changed event something like this would work...
textprice.text = Combobox.selecteditem.value
This will give you a great start, that's why this answer just gives you the steps and not the full code.

one problem in fetching a data from backend in vb.net

i have two item in form it is---1 is textbox and 2nd is combo box.
now i have single value in textbox .
but there is a multiple value for a combobox with is totally depend on a value of textbox....
*i am already add data to the backend files ... in which 1 columns that is called column A it's value is for textbox and 2 column that is called column B it's value for combo box *
When i write in textbox it's dependent ALL value can be get in the combo box.
Can any one solve my problem... It is a row vice search.....
I used a Ms Access for my backend......
How i can create a table that can be i used for a my problem
Give me any reference or codes.
This is probably Category->Product kind of scenario, where ONE Category can have ONE or MORE Products,
Category "Softdrink" can have Products("Coke","Pepsi" etc.)
Category "Harddrink" can have Products("8 PM","BP",etc.)
So when u will put "Softdrink" in your textbox then you want to get the relevant products for it. (Assumed you are using TextChange event)
SQL - select Product.Name from Category Inner Join Product On Category.Id= Product.Category_Id where CategoryName ="Softdrink"
and table structure would be like,