Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 13th, 2006, 01:09 PM
Registered User
 
Join Date: Oct 2006
Location: Goddard, Ks, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with highlighting text in a combo box

I have a database w/ employees and a form from which I can search for a specific lastname, firstname, etc. I have combo boxes for each field that I can search from in the form header and then a row of text boxes in the detail section to return my results. My problem is that after my cboLASTNAME.setfocus command I want the text in the combo box to highlight so that I can just type the next name without having to move the mouse and highlight the info myself. Any ideas on how to do this? I've tried the .Selstart and .Sellength with no luck.

Any help would be greatly appreciated.

Reply With Quote
  #2 (permalink)  
Old October 13th, 2006, 02:12 PM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

You need to attach the code to the proper event. I have a form that I frequently check a check box, and I use this event and code to go back to my combo box to look up the next record.

Private Sub CheckBox_AfterUpdate()
Me.MyCombo.SetFocus
End Sub

I also find this code helpful on the GotFocus event of the combo box:

Private Sub MyCombo_GotFocus()
    Me!MyCombo.Dropdown
End Sub

So the focus jumps back to the combo, and it pops down so I can start looking up right away.

Does this help?

mmcdonal
Reply With Quote
  #3 (permalink)  
Old October 13th, 2006, 03:39 PM
Registered User
 
Join Date: Oct 2006
Location: Goddard, Ks, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I run a function that runs my query and gathers all of my results for each combo box. The code is quite long so I dont know if I should post it here. is there a way I could attach a txt file or something to be viewed?

The combo box has every last name in it when I drop down until I run the first search. Lets say I search for 'Smith' It will pull up all the 'Smith's' in the database and then setfocus back to the cboLASTNAME where 'Smith' is still there and I need to type a new name. I have to use the mouse to go up and highlight it in order to type a new name over the old one for the next search. Everything I have read says to use a GotFocus w/ this code.

me.cboLASTNAME.Selstart = 0
me.cboLASTNAME.SelLength = Len(me.cboLASTNAME.text)

But I get an error of invallid use of Null or something like that.

If there is no limit on length of code to post I can do that or else I can send it to someone to take a look at.

Reply With Quote
  #4 (permalink)  
Old October 18th, 2006, 07:22 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

This sounds odd. If you're in the first combobox and type in or choose a value, and then TAB to the second combobox, Access's behavior is to automatically highlight the entire contents of the second combobox. Don't click... tab.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Reply With Quote
  #5 (permalink)  
Old October 18th, 2006, 07:57 AM
Registered User
 
Join Date: Oct 2006
Location: Goddard, Ks, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I mainly just search from the first combo box (cboLastName), unless I need to use first name or department number etc... I type in the last name and hit enter and then below it will pull up the results and setfocus back to (cboLastName). Now after I search for the first person my combo box empties all the info in it so when I click on the dropdown it is blank w/ zero data in it (which is fine) except my entry that I had just typed in. I just need to figure out how to get my previous entry, that I typed into the (cboLastName) to highlight so I can type over it without having to use the mouse to move over and highlight it manually.

Reply With Quote
  #6 (permalink)  
Old October 18th, 2006, 08:51 AM
Registered User
 
Join Date: Oct 2006
Location: Goddard, Ks, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the code I am using for (cboLASTNAME) the other 6 combo's are the same so if I can figure this one out I can fix the others.

Private Sub cboLASTNAME_AfterUpdate()
Call FormFilter
End Sub

Private Sub cboLASTNAME_DblClick(Cancel As Integer)
Me.cboLASTNAME = ""
Call FormFilter
End Sub

Function FormFilter()
Dim sql As String
Dim strCrit As String
Dim sqlLastname As String
Dim sqlLastname1 As String
Dim sqlFirstname As String
Dim sqlFirstname1 As String

sql = "SELECT qryEmployeeInfo.LastName, qryEmployeeInfo.FirstName, qryEmployeeInfo.DepartmentNumber, qryEmployeeInfo.BuildingNumber, qryEmployeeInfo.DepartmentName, qryEmployeeInfo.MailSlotID, qryEmployeeInfo.PlantIndicator,qryEmployeeInfo.Ter minated,qryEmployeeInfo.ID " & _
        "FROM qryEmployeeInfo"

sqlLastname = "SELECT qryEmployeeFilter.LastName FROM qryEmployeeFilter"
sqlLastname1 = " GROUP BY qryEmployeeFilter.LastName ORDER BY qryEmployeeFilter.LastName;"

If IsNull(Me.cboLASTNAME) Or Me.cboLASTNAME = "" Then
    strCrit = ""
Else
    strCrit = " WHERE [LastName] Like '" & Me.cboLASTNAME & "'"
End If

If IsNull(strCrit) Or strCrit = "" Then
    Me.RecordSource = sql
    Me.cboLASTNAME.RowSource = sqlLastname & sqlLastname1
Else
    Me.RecordSource = sql & strCrit
    Me.cboLASTNAME.RowSource = sqlLastname & strCrit & sqlLastname1
End If
End Function

Me.Requery
Me.cboLASTNAME.Requery
me.cboLASTNAME.SetFocus


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Populate a text box from a combo box value dnf999 Access VBA 7 February 6th, 2012 02:24 PM
Count in combo box(display results in text box) mboyisis Access 4 April 4th, 2008 07:08 AM
highlighting the word in rich text box AnurRS C# 0 May 31st, 2006 06:41 AM
Combo box and Text box Rudner Access VBA 4 November 16th, 2004 02:57 PM
Combo Box and Text Box Rudner Beginning VB 6 1 November 8th, 2004 04:48 PM



All times are GMT -4. The time now is 07:54 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.