I'm not quite ready to give up on this yet... Using MS Access 2003, WinXP SP2.
I have a listbox that I'm trying to get to highlight (select) a specific record using the GotFocus event (the listbox setfocus is passed by a combobox afterupdate event).
The code I have is: -
Private Sub lstRate_GotFocus()
-
Dim rs As DAO.Recordset
-
Dim SelDate As Date
-
'Dim MyVarBM As Long
-
-
SelDate = DMax("[DateChange]", "tblDate")
-
Set rs = Me.lstRate.Recordset
-
With rs
-
.MoveLast
-
.FindFirst "[DateChange] = #" & SelDate & "#"
-
If .NoMatch Then
-
MsgBox "No Match Found"
-
End If
-
End With
-
End Sub
The code executes fine, the list box recieves the focus, .nomatch is set to false, the variables populate as desired... However the desired record is not highlighted in the listbox!
Anyone able to help me here??
Thanks in advance!
Regards,
Scott
5 7754 JKing 1,206
Recognized Expert Top Contributor
Hi there, what is the record source of the list box?
I think the basic logic of what you want to do is to loop through the items in your listbox until a column value = your criteria. Once found grab the row and pass that into the Selected property and set it to true. This will "highlight" or select the record you want.
So perhaps you can give some insight as to what the criteria is being based off and what info is in your listbox.
Hi there JKing...
The record source of the listbox is this query in the Row Source: - SELECT tblDate.DateID, tblDate.DateQuarter, tblDate.InvoiceNo, tblDate.QOrderID, tblDate.DateChange FROM tblDate;
I'll try the selected property and get back to you...
Thanks!
Regards,
Scott
JKing 1,206
Recognized Expert Top Contributor
Here's a quick and dirty example of looping through the listbox and setting the selected property. -
Dim intCount As Integer
-
For intCount = 0 To Me.List10.ListCount - 1
-
If Me.List10.Column(0, intCount) = "Some Value" Then
-
Me.List10.Selected(intCount) = True
-
End If
-
Next
-
The Column property takes in a column position starting at 0 and then a row number also starting at 0. If you want to look at the first column in the first row it would be Column(0,0). Third column 10 row would look like (2,9). I'm sure you get the picture.
Any further questions let me know and good luck!
Thanks again JKing... You gave me the nudge on the right direction... This is the code I came up with that finally worked: - Private Sub lstDate_GotFocus()
-
Dim rs As DAO.Recordset
-
Dim SelDate As Date
-
Dim MyVarBM As Long
-
-
SelDate = DMax("[DateChange]", "tblDate")
-
Set rs = Me.lstDate.Recordset
-
With rs
-
.MoveLast
-
.FindFirst "[DateChange] = #" & SelDate & "#"
-
MyVarBM = .AbsolutePosition 'returns the row # of the offending record
-
'Debug.Print MyVarBM
-
Me!lstDate.Selected(MyVarBM) = True 'selects the offending row
-
If .NoMatch Then
-
MsgBox "No Match Found"
-
End If
-
End With
-
End Sub
Thanks again,
Regards,
Scott
JKing 1,206
Recognized Expert Top Contributor
Great, glad you got things working. Sometimes all you need is that little nudge.
Jared
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Skully Matjas |
last post by:
I am using the following code (created by the wizard) to
allow to bring my form to a particular entery. But when I
edit the entery (ex: put new information into a blank
cell), it puts that record onto the bottom of the list
(even though it keeps its record number).
Also, There are certin names that i click on the list, and
it will not bring it up, rather it brings to the first
record (no matter how many times i try going to that...
|
by: Skully Matjas |
last post by:
Thank you for getting back to me. I am very new at this so i didnot
understand what you said, here i will give as much cetails as possible:
1) The combo box i am using is combox39
2) I imported a a table of parents of a school (it has name,address,#,
etc...)
3) I nead to input a ID Number (ralphs card) for some of the parents
4) The ID numbers do not go inorder of the parents, and i am not being
handed the id numbers in order
4) I want...
|
by: Danny J. Lesandrini |
last post by:
The following code works with a standard MDB to navigate
to a particluar record (with a DAO recordset, of course)
but it's giving me problems in an ADP I'm working on.
Dim rs As ADODB.Recordset
Set rs = Me.RecordsetClone
rs.Find "=" & lngContractID
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
I must site the Heisenberb Uncertainty Principal here, as it
|
by: Geir Baardsen |
last post by:
Hi!
On frmItems I have a two listboxes. The first, lstAllCategories, is
loaded with data from tblCategory when frmItems open. When user click
lstAllCategories, the lstSelectedItems will show all records for that
category.
Now when user clicks chosen item in lstSelectedItems, textboxes in
form will be filled and now user can edit the selected item.
|
by: MS |
last post by:
Access 97
I want to requery the data being displayed on a form, then I want to return
to the record I was in.
Why doesn't this code work?
Private Sub CmdRefsh_Click()
| |
by: Zlatko Matić |
last post by:
There is a form (single form) and a combobox. I want that current record of
the form is adjusted according to selected value in the combobox. Cuurrent
record should be the same as the value in the combobox.
What is the solution?
Thank you in advance.
|
by: ApexData |
last post by:
Hello
How do I goto a specific record in a BOUND form when the form has a
primary
index of ID which is autonumbered. I need to visit 4 seperate records,
one at a time.
This works for RecNO but no good for Field search: DoCmd.GoToRecord ,
, acGoTo, 19
And I know is NOT recommended.
|
by: boyleyc |
last post by:
Hi all
I have written a database in access and used ADODB recordsets all the
way through. The only recordsets that are not ADODB are the listbox
navigation code automatically generated by access 2003 as follows :
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
|
by: boliches |
last post by:
I am trying to get a continuous form to highlight lines individually (ideally on hover). I have used the following code as recommended by a previous entry on this website. My problems begin in that my Database does not appear to recognise "FindFirst". The sample database I downloaded for help does recognise the script and when I begin to type the drop down gives the prompt for "FindFirst"! Why is it that my MDB does not? The only drop downprompt...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |