listbox & Setfocus

  • Thread starter Thread starter dave h
  • Start date Start date
D

dave h

Hi,

Me!myListBox.RowSource = mySQL
Me!myListBox.Setfocus

why would this code produce this error:

"you must save the field before ..... the Setfocus method"

Thanks, Dave H
 
Hi Dave,

what is the content of the mySQL string, as what you have done should
work, personally I put a me.mylistbox.requery in between the two lines
just to make sure that the list box refreshes before setting the focus
but your code should work.

Regards

Alex
 
Hi Alex,

Thanks for the response. The SQL is fairly complicated (you can see it
below), but it works just fine without the set focus. However, the use must
select the first row manually to utilize it in a subsequent button click
activity. Most often, they will want to start with the first row (and often
there is only one row) so it would be a nice feature to start with the first
row already selected.

What is is also odd is the fact that I can use
myListBox.Selected(0) = True
and the row gets highlighted, but my code still does not recognize the data
from the row until the user actually clicks the row.

Any more insights will be greatly appreciated.

------------------------------------------
mySQL = "SELECT i.CategoryID & '.' & i.subCategoryID & '.' & i.AreaID &
'.' & i.SubAreaID & '.' & i.ItemUniqueID AS dotID, "
'1
mySQL = mySQL & " i.itemName, li.CopyNumber, ld.CheckOutDate,
ld.shipDate, ld.DueDate, ld.CheckInDate, ld.notes, ld.LoanDetailID,
li.InventoryID " '9
mySQL = mySQL & " FROM Customer_1 AS c, Loan_34 AS lo, LoanDetail_214 AS
ld, LibraryInventory_33 AS li, LibraryItems_27 as i "
mySQL = mySQL & " WHERE i.itemID = li.itemID "
mySQL = mySQL & " AND li.InventoryID = ld.InventoryID "
mySQL = mySQL & " AND ld.loanID = lo.LoanID "
mySQL = mySQL & " AND lo.customerID = c.customerID "
mySQL = mySQL & " AND lo.LoanDate > #" & StartDate & "# "
mySQL = mySQL & " AND lo.LoanDate < #" & EndDate & "# "
mySQL = mySQL & " AND c.customerID = " & ckInCustomerID
mySQL = mySQL & " AND lo.loanID = " & cboLoanID

-----------------------------------Note that all the variables have valid
values when it errors

Again the original error was:"you must save the field before ..... the
Setfocus method"
for the code:
Me!myListBox.RowSource = mySQL
Me!myListBox.Setfocus
 
Well it seems that the suggestion I got from Marsh concering a similar issue
with a combo box has served well for this problem.
He suggested using

Me.Combo = Me.Combo.ItemData(0)

This also works well with my list box issue.
 
Back
Top