How to stop Access highlight the text in a combo box after an event

P

Paul

I have a combo box with an "On Change" event. The code will execute a vba
code. Upon completion of the "On Change" event, I expect the position of the
cursor move to the right side of the text. Instead it highlights the entire
text. How to position the cursor to the right side of the text after the
event. For example I typed in letter A, the position of the cursor should be
on the right side of the A like "A_" but not highlight the A.

The following is the "On Change" event code:
Private Sub cboProduct_Change()
Me.btnClose.SetFocus
If IsNull(Me.cboProduct) Or Me.cboProduct = "" Then
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form.RecordSource = ""
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![Product].ControlSource = ""
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![StockNumber].ControlSource = ""
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![PotSize].ControlSource = ""
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![Location].ControlSource = ""
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![StockNumberNotes].ControlSource = ""
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![Quantity].ControlSource = ""
Else
Requery
Refresh
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form.RecordSource = "SELECT Tbl_Product.Product,
Tbl_Inventory.StockNumber, Tbl_Inventory_Detail.PotSize,
Tbl_Inventory_Detail.Location, Sum(Tbl_Inventory_Detail.Quantity) AS
SumOfQuantity, Tbl_Inventory_Detail.StockNumberNotes " & _
"FROM (Tbl_Product INNER JOIN Tbl_Inventory ON Tbl_Product.ProductID
= Tbl_Inventory.ProductID) INNER JOIN Tbl_Inventory_Detail ON
Tbl_Inventory.InventoryID = Tbl_Inventory_Detail.InventoryID " & _
"GROUP BY Tbl_Product.Product, Tbl_Inventory.StockNumber,
Tbl_Inventory_Detail.PotSize, Tbl_Inventory_Detail.Location,
Tbl_Inventory_Detail.StockNumberNotes " & _
"HAVING (((Tbl_Product.Product) Like """ & [Forms]![Frm_Quick
Search]![cboProduct] & "*" & """));"
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![Product].ControlSource = "Product"
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![StockNumber].ControlSource = "StockNumber"
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![PotSize].ControlSource = "PotSize"
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![Location].ControlSource = "Location"
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![StockNumberNotes].ControlSource = "StockNumberNotes"
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![Quantity].ControlSource = "SumOfQuantity"
End If
Me.cboProduct.SetFocus
Requery
Refresh
End sub
 
D

Dan Artuso

Hi,
Add this as the very last line:
Me.cboProduct.SelStart = Len(Me.cboProduct) + 1

--
HTH
Dan Artuso, Access MVP


Paul said:
I have a combo box with an "On Change" event. The code will execute a vba
code. Upon completion of the "On Change" event, I expect the position of the
cursor move to the right side of the text. Instead it highlights the entire
text. How to position the cursor to the right side of the text after the
event. For example I typed in letter A, the position of the cursor should be
on the right side of the A like "A_" but not highlight the A.

The following is the "On Change" event code:
Private Sub cboProduct_Change()
Me.btnClose.SetFocus
If IsNull(Me.cboProduct) Or Me.cboProduct = "" Then
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form.RecordSource = ""
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![Product].ControlSource = ""
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![StockNumber].ControlSource = ""
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![PotSize].ControlSource = ""
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![Location].ControlSource = ""
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![StockNumberNotes].ControlSource = ""
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![Quantity].ControlSource = ""
Else
Requery
Refresh
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form.RecordSource = "SELECT Tbl_Product.Product,
Tbl_Inventory.StockNumber, Tbl_Inventory_Detail.PotSize,
Tbl_Inventory_Detail.Location, Sum(Tbl_Inventory_Detail.Quantity) AS
SumOfQuantity, Tbl_Inventory_Detail.StockNumberNotes " & _
"FROM (Tbl_Product INNER JOIN Tbl_Inventory ON Tbl_Product.ProductID
= Tbl_Inventory.ProductID) INNER JOIN Tbl_Inventory_Detail ON
Tbl_Inventory.InventoryID = Tbl_Inventory_Detail.InventoryID " & _
"GROUP BY Tbl_Product.Product, Tbl_Inventory.StockNumber,
Tbl_Inventory_Detail.PotSize, Tbl_Inventory_Detail.Location,
Tbl_Inventory_Detail.StockNumberNotes " & _
"HAVING (((Tbl_Product.Product) Like """ & [Forms]![Frm_Quick
Search]![cboProduct] & "*" & """));"
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![Product].ControlSource = "Product"
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![StockNumber].ControlSource = "StockNumber"
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![PotSize].ControlSource = "PotSize"
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![Location].ControlSource = "Location"
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![StockNumberNotes].ControlSource = "StockNumberNotes"
Forms![Frm_Quick Search]![Frm_Quick Search
Subform].Form![Quantity].ControlSource = "SumOfQuantity"
End If
Me.cboProduct.SetFocus
Requery
Refresh
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