My Assistant
![]() ![]() |
|
|
Apr 13 2006, 10:12 PM
Post
#1
|
|
|
UtterAccess Member Posts: 29 From: California |
Is there a way to GetFocus and also Select (or in effect, CLICK) on an item in a combo box -- using VB??
Thank you all for any response. |
|
|
|
Apr 14 2006, 12:13 AM
Post
#2
|
|
|
UtterAccess VIP Posts: 20,210 From: Colorado |
me.controlname.setfocus
me.controlname.dropdown |
|
|
|
Apr 14 2006, 01:21 AM
Post
#3
|
|
|
UtterAccess Member Posts: 29 From: California |
Hello, again;
I tried placing the above code into my ON Load event in my form. I received the following error: Method or data member not found! Regarding your prior reply, I had a typo in my example. 1800 hours as a number, not text. Again, after I open my form, all I have to do is to click and highlight the 1800 as it appears in my TimeInCheck combo/query result, and then when I click on any other input combo, the code works fine. I get my error message, and the TimeIn combo is disabled. Perfect. We are almost there. The only thing I need to know is how to highlight the data in the TimeInCheck combo, so that the code can interpolate the IF statement. ?? |
|
|
|
Apr 16 2006, 01:48 AM
Post
#4
|
|
|
UtterAccess VIP Posts: 20,210 From: Colorado |
Hi Chuck,
"Method or data member not found!" means you did not use the right name for the control when I used "controlname", I meant for you to substitute what is in the NAME property of the control, not its ControlSource (which is what you see in there in design view) -- turn on the property sheet and look to see what the Name is. If it is not logical, then change it. That is what you need to use (don't use spaces in the name -- save yourself that headache) [qupte]We are almost there. The only thing I need to know is how to highlight the data in the TimeInCheck combo, so that the code can interpolate the IF statement.[/quote] your code shoud determine if somthing is actually filled out first ... CODE if IsNull(me.controlname) then 'nothing is specified 'perhaps give user a message? Exit sub end if Why would you want tp pick a value for them? That would lead to data entry errors because they would not realize that THEY did not choose it... |
|
|
|
Apr 16 2006, 03:23 AM
Post
#5
|
|
|
UtterAccess Member Posts: 29 From: California |
Hello, Crystal:
Thank you for your continued patience. Using your suggested code from above, I did realize that I had to use the name of my controls, and did so. I entered Me.TimeInCheck.SetFocus Me.TimeInCheck.Dropdown The method not supported is the problem. Dropdown is not a recognized method in 2003 v11?? At any rate, let me explain why I am trying to "autoselect" the data in the listbox. My form is used for workorder data entry for employees. Each employee has their own data entry form. One of the controls is a TimeIn List box from which they click a punch in time. This control is sourced to my table TimeIn field. I also have a TimeOut listbox for the same purpose. Each employee opens their own unique data entry form. There are some differences between employees so I thought it easier to create unique forms for each employee. The workers are required to enter all their jobs, time per job, equipment job center, etc. Some of the workers sit down at the end of the day to enter all that day's jobs in one sitting. Others enter them as their day progresses. At any rate, I do not want them to be able to enter their TimeIn and TimeOut times more than once per day. As long as they keep their form open, the TimeIn and TimeOut boxes disable after the first entry. But If I close the form and reopen it (as they might do during the day), then the TimeIn and TimeOut listboxes are once again enabled. The disable does not carry over to the next reopen of the form. So, I have another list box on the form that is populated by the results of a duplicate query. If a TimeIn has been entered for the day, the TimeIn (say in this case 1800 hrs.) is result of the query which runs in my form's OnOpen event, and the result shows up in my List box (TimeInCheck) when the form is opened subsequently. Using the following: Private Sub TimeIn_Click() Me.TimeInCheck.SetFocus If Me.TimeInCheck.Value > 0 And Not IsNull(Me.TimeInCheck.Value) Then DoCmd.RunMacro "TimeInCheckMessage" Me.SetSystem.SetFocus Me.TimeIn.Enabled = False Me.Time_Out.Enabled = False Else Me.TimeIn.Enabled = True Me.Time_Out.Enabled = True Me.TimeInCheck = Me.TimeIn End If End Sub I have tried this in the form's OnLoad, AfterUpdate, BeforeUpdate, OnActivate, etc. The only way this works is if after opening the form, I actually click on Me.TimeInCheck (which highlights the time in the cell). Then, when I click on the TimeIn listbox to attempt entering a second TimeIn, this code works well, causing my message macro to run and disables the TimeIn TimeOut listboxes. Make sense? I realize my approach may be unorthodox, but I am not a programmer either. Maybe you have some insight to how I can accomplish what I am trying to do. Thank you much, Crystal. Best regards. |
|
|
|
Apr 16 2006, 11:42 AM
Post
#6
|
|
|
UtterAccess VIP Posts: 20,210 From: Colorado |
Hi Chuck,
CODE 'if your combo has Headers -->
Me.TimeInCheck= Me.TimeInCheck.ItemData(1) 'if your combo has No Headers --> Me.TimeInCheck= Me.TimeInCheck.ItemData(0) 'When you change the value using code, you will also have to launch your procedure --> TimeIn_Click |
|
|
|
Apr 20 2006, 04:41 AM
Post
#7
|
|
|
UtterAccess Member Posts: 29 From: California |
Crystal:
Fine business! That works perfectly. Mission accomplished! The following is the code I am now using in my TimeIn Listbox ON Click Event: Me.TimeInCheck = Me.TimeInCheck.ItemData(0) If Me.TimeInCheck > "0" Then Me.TimeIn = "" DoCmd.RunMacro "TimeInCheckMessage" Me.SetSystem.SetFocus Me.TimeIn.Enabled = False Me.Time_Out.Enabled = False Else Me.TimeIn.Enabled = True Me.Time_Out.Enabled = True Me.TimeInCheck = Me.TimeIn End If Such a headache, and yet with your persistent help, such an easy solution. Thank you very much. See you on UA. |
|
|
|
Apr 26 2006, 07:47 PM
Post
#8
|
|
|
UtterAccess VIP Posts: 20,210 From: Colorado |
you're welcome, Chuck (IMG:http://www.utteraccess.com/forum/style_emoticons/default/wink.gif) happy to help
|
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 23rd May 2013 - 11:21 PM |