rs need help (1 Viewer)

shobhanauto

New member
Local time
Today, 10:40
Joined
Dec 17, 2023
Messages
15
hi
i need another help
I uploaded the database file.

In the forms, the last Sell% shows 3.53%. Then the result should update in the ItemName tables SalesPercents field.

I added the VBA code, but it's not working.
Can anyone help?
Could someone please help me?
 

Attachments

Last edited:
Unfortuntely, calculated columns are not editable. If you must be able to edit the values, then you have to use a regular field.
 
You need to have a field "ManualPrice"
if the manual price <> 0 then display manual price else display [mrp] * [discount]
 
RS
=IIf([ManualPrice]>0,[ManualPrice],[MRP]*[DISCOUNT])
 
i need another help
I uploaded the database file.

In the forms, the last Sell% shows 3.53%. Then the result should update in the ItemName tables SalesPercents field.

I added the VBA code, but it's not working.
Can anyone help?
 
What code, Where? We are not mystics.
Dear Sir i Uploaded database file first page

and here vb code i set SalesPercents

Code:
Private Sub SalesPercents_Click()
    On Error GoTo ErrorHandler
    
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    
    Set db = CurrentDb()
    Set rs = db.OpenRecordset("SELECT * FROM ItemName", dbOpenDynaset)
    
    Do While Not rs.EOF
        rs.Edit
        rs("SalesPercents") = 1 - (rs("BDDUTY") / rs("RePrice"))
        rs.Update
        rs.MoveNext
    Loop
    
    rs.Close
    Set rs = Nothing
    Set db = Nothing
    Exit Sub

ErrorHandler:
    MsgBox "Error " & Err.Number & ": " & Err.Description
End Sub
 
why is your code triggered in the detail section of your form? Is the intention you want to update all records or just the one you are on? Why not just use an update query rather than looping through a recordset?

Salespercents is a text field (shouldn't it be numeric?) in your table but a calculated control on your form - so you would need to look in the table to see if your code has worked

BDDuty is a field in your table, but a calculated value on your form and you code is referencing the table version of its value not the form version

And since these are calculated values - why do you want to store them?

Many of the values you use in your calculation are null (or perhaps zls) so will result in a null value.

If you step through your code you can check the values used in your calculation.
 
why is your code triggered in the detail section of your form? Is the intention you want to update all records or just the one you are on? Why not just use an update query rather than looping through a recordset?

Salespercents is a text field (shouldn't it be numeric?) in your table but a calculated control on your form - so you would need to look in the table to see if your code has worked

BDDuty is a field in your table, but a calculated value on your form and you code is referencing the table version of its value not the form version

And since these are calculated values - why do you want to store them?

Many of the values you use in your calculation are null (or perhaps zls) so will result in a null value.

If you step through your code you can check the values used in your calculation.
And since these are calculated values - why do you want to store them?

The reason for storing this is because I have three sales forms for three branches. When I update Salespercents, it will be displayed next to ItemName on these forms. For users generating invoices, the Salespercents I set will prevent selling below that specified percentage.

In my Analysis Form, this setup helps in analyzing items based on the updated Salespercents.
 

Users who are viewing this thread

Back
Top Bottom