Choosing between unit price and total price

C

ceryesb

Hey I'm using access to keep track of orders and generate invoices. The
documents I copy into the database sometimes give me a unit price and
quantity and other times only give me a total price and quantity. I'd
like to be able to enter in either depeneding on what I am given and
have either the unit price or the total price automatically calculated.
The way it's set up now I can only enter a unit price and quantity and
it calculates the total price for me. It's nothing I can't do without
a calculator but I figured there must be a way to do it. Thanks alot
for your help.
 
U

UpRider

Put these subs in the form's module for the 3 text boxes.
There is no data validation included to check for entry of zero or non
numerics.
HTH, UpRider

Private Sub txtQty_AfterUpdate()
If Len(txtUnitPrice & txtTotalPrice & vbNullString) = 0 Then Exit Sub
If Len(txtUnitPrice & vbNullString) > 0 And Len(txtTotalPrice &
vbNullString) > 0 Then
MsgBox "Both Unit Price and Total Price are already filled in. One
or the other must be " _
& "blank.", vbOKOnly, " I N P U T P R O B L E M "
Exit Sub
End If
If Len(txtUnitPrice & vbNullString) > 0 Then
txtTotalPrice = txtQty * txtUnitPrice
Exit Sub
End If
If Len(txtTotalPrice & vbNullString) > 0 Then
txtUnitPrice = txtTotalPrice / txtQty
Exit Sub
End If
End Sub

Private Sub txtTotalPrice_AfterUpdate()
If Len(txtQty & vbNullString) > 0 And Len(txtTotalPrice & vbNullString)
txtUnitPrice = txtTotalPrice / txtQty
Exit Sub
End If

End Sub

Private Sub txtUnitPrice_AfterUpdate()
If Len(txtQty & vbNullString) > 0 And Len(txtUnitPrice & vbNullString) >
0 Then
txtTotalPrice = txtUnitPrice * txtQty
Exit Sub
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top