setfocus on Current

G

Guest

I have a lstBox (lstVisit) that displays the date and type of patient
procedure, on the click event in the lstVisit the info for the particular
visit that was clicked on is loaded into the frmVisit (which is a fsub to
frmPtDemographics). In the Current event of the frmVisit I have
Me.lstVisit.SetFocus. Here's the probem;

When the forms initially loads, all is fine, the most current record in the
list box is highlighted and the visit info is loaded correctly. But when I
move to another patient record (thru a search screen), the lstbox is not
recieving the focus, and thus not on the most current visit with it's
corresponding visit info loaded into frmVisit. I can't figure out why the
list is not getting the focus with the most current visit highlighted and the
visit info loaded into frmVisit.

Any help would be greatly appreciated. Thanks, Rob
 
G

Guest

Based on your description, it appears lstVisit is not a bound control.
Unbound controls have no knowledge of what record you are on. You will have
to code into your Current event a procedure that will make the current record
the selected record in the list box.

Take a look at the Selected property in VBA Help. There is a good example
there of how you can loop through the items in a list box and make them
either Selected or not.
 
G

Guest

Klatuu, Thanks for the respones. I placed Me!ListBox.Selected(0) = True in
the Current event and got the msg that didn't work. Do you have any ideas?
Pls remember, I pretty much the rookie VBA guy.

Thanks,
Rob
 
G

Guest

What message and/or error number did you get?
Did you replace "ListBox" with the actual name of the list box on your form?
 
G

Guest

I replaced ListBox with lstVisit. I get the following error msg; Error 3075
(syntax error(missing operator) in query expression 'VisitNo=') in procedure
lstVisit_Click of VBA document.

Rob
 
G

Guest

Private Sub lstVisit_Click()


On Error GoTo lstVisit_Click_Error

Me.Filter = "VisitNo = " & Me.lstVisit.Value
Me.FilterOn = True

On Error GoTo 0
Exit Sub

lstVisit_Click_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
lstVisit_Click of VBA Document Form_frmVisitNewEdit"

End Sub
*******************************************************
I don't get this error msg when I take out the lstSelect code. Rob
 
G

Guest

Me.Filter = "VisitNo = " & Me.lstVisit.Value

The above syntax assumes VisitNo is a field in the form's recordset that is
a numeric value. If VisitNo is a text field, it should be:
Me.Filter = "VisitNo = '" & Me.lstVisit.Value & "'"
 
G

Guest

The VisitNo is a numeric field, it is a auto# key field for tblVisit. As I
said, I don't get the message when I take out Me!lstVisit.Selected(0) = True.
But that puts me right back where I started, I can't get the focus on
lstVisit and the most recent visit selected. what do you think?

Rob
 
G

Guest

Well, that code was not part of what you posted previously, but I can't
determine the problem. I tested a version of the line that is causing the
problem and it is working fine for me. Here is mine:
frm.lstbillprodoffering.selected(3) = true

Now, a question. Is this a multi select list box?
 
G

Guest

Klatuu, I'm sorry for not responding more quickly. For some reason I thought
that I had posted the 9th post (this 10) and thought you hadn't responded.
Again, sorry, my bad. It is not a multiselect. Do you want me to post the
code for the entire module? Hope you're still answering posts. Thanks, robert
 
G

Guest

Yes, but I will be leaving in the next 30 minutes, so I may not see it until
Monday.
Enjoy the Superbowl

FYI, I may be working multiple questions at the same time and sometimes they
actually expect me to do some work here <g>, but I do try to answer as
quickly as I can.

Hopefully, you are aware we are all volunteers here. Just Access Junkies
trying to help others. Microsoft supplies the site, but everyone here does
it to help support the Access community.
 
G

Guest

Thanks Klatuu, I'll post again tomorrow. I do appreciate that you and the
others are volunteers. I would be sunk without you guys. Thank again and have
a great weekend. Rob
 

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