Return to last cursor??

S

SF

Hi,

I have a tabular form (bound to a temporaty table) consist of 3 columns
(ProductID, Qty, Unit Price). User has to type in the product ID and in the
updtae event I did a lookup to see if the product Code is realy exist in the
product table, if yes fill the (preset) Unit Price, If no, display an error
message and return to the last field.

My problem is that I caanot return the cursor to the Product ID last
positioned, unstead, cursor is moving down to the ProductID of new record.

Could someone advice

SF
 
D

Dale Fye

SF,

Are you using the controls BeforeUpdate or AfterUpdate event.

If you use the BeforeUpdate you could do something like:

Private sub txt_ProductID_BeforeUpdate(Cancel as integer)

dim varUnitPrice as Variant
dim strCriteria as string

strCriteria = "[ProductID] = " & me.txt_ProductID
varUnitPrice = DLOOKUP("Unit Price", "TempTableName", strCriteria)
If isnull(varUnitPrice) then
msgbox "Invalid Product ID"
Cancel = true
Else
me.txt_UnitPrice = varUnitPrice
endif

End sub

HTH
Dale
 
P

Pat Hartman

You need to trap the error in the form's BeforeUpdate Event. Cancel the
update and set the focus back to the productID.

Cancel = True
Me.ProductID.SetFocus
 
S

SF

Hi Dale,

It works perfectly.

SF

Dale Fye said:
SF,

Are you using the controls BeforeUpdate or AfterUpdate event.

If you use the BeforeUpdate you could do something like:

Private sub txt_ProductID_BeforeUpdate(Cancel as integer)

dim varUnitPrice as Variant
dim strCriteria as string

strCriteria = "[ProductID] = " & me.txt_ProductID
varUnitPrice = DLOOKUP("Unit Price", "TempTableName", strCriteria)
If isnull(varUnitPrice) then
msgbox "Invalid Product ID"
Cancel = true
Else
me.txt_UnitPrice = varUnitPrice
endif

End sub

HTH
Dale

--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.



SF said:
Hi,

I have a tabular form (bound to a temporaty table) consist of 3 columns
(ProductID, Qty, Unit Price). User has to type in the product ID and in
the
updtae event I did a lookup to see if the product Code is realy exist in
the
product table, if yes fill the (preset) Unit Price, If no, display an
error
message and return to the last field.

My problem is that I caanot return the cursor to the Product ID last
positioned, unstead, cursor is moving down to the ProductID of new
record.

Could someone advice

SF
 

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