PDA

View Full Version : Solved: Using the return key as a tab



seeking_help
06-16-2008, 08:32 AM
Hi all,
I am trying to use the return key as a tab in VBA. I have set the tab order so when i hit enter it will go to the next tab order but it does not trigger my KeyUp event in turn, will not populate my box(want i really want to do). I want to tab into a combo box and have that be populated with my info so the user doesn't have to mouse click the dropdown arrow. Any ideas on why the event is not being triggered?

-----------------------------------------------------------------------
sample code below...

Private Sub tbDiffProjJobNum_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then ' enter key
KeyCode = 0
Call Combo0_GotFocus ' sub being called to fill combo box
MsgBox "hi" ' test to see if event occurs
End If
End Sub

-----------------------------------------------------------------------

Thanks for any help!

CreganTur
06-16-2008, 09:29 AM
I want to tab into a combo box and have that be populated with my info

Exactly what info are you wanting to be entered into the combo box? Is this info based on the results of a table, is it dependant on the value of another field in your form? Is it based on who the logged on user is...?

Knowing this will help us to figure out exactly what you're trying to accomplish.

seeking_help
06-16-2008, 10:02 AM
Sorry about that, here is what is going on.
I work at an Engineering company, and i wrote a program to make it easier/faster to copy blocks(for example a lighting fixture) for Acad. You have the choice to copy from the master database, the current project, or from an existing project. My problem is in an existing project. The user inputs a job number for example 2350 and is sent to the correct folder(job#) to access the block they wish to copy. If the job# is correct then the list of all the possible blocks then is put into the combo box. The info displayed is the Fixture Type and the Fixture Size.

-----------------------------------------------------------------------
' code that populates the combo box

strAPPath = "G:\job#\#" + Left(tbDiffProjJobNum.Value, 2) + "00-" + Left(tbDiffProjJobNum.Value, 2) + "99\" + tbDiffProjJobNum.Value + "\Access\ELECTRIC.mdb"
Set dbAnotherProject = OpenDatabase(strAPPath)
Set rstAnotherProject = dbAnotherProject.OpenRecordset("SELECT * FROM Luminaire_Schedule order by Fixture_Type")
'populate combo box
While Form_frmPickFixture.Combo0.ListCount <> 0
Form_frmPickFixture.Combo0.RemoveItem (0)
Wend
rstAnotherProject.MoveFirst
While Not rstAnotherProject.EOF
strInfo = rstAnotherProject.Fields("Fixture_Type")
If rstAnotherProject.Fields("Description") <> "" Then
strDesc = rstAnotherProject.Fields("Description")
Else
strDesc = " "
End If
If rstAnotherProject.Fields("Size") <> "" Then
strSize = rstAnotherProject.Fields("Size")
Else
strSize = " "
End If
Form_frmPickFixture.Combo0.AddItem strInfo & " - " & strDesc & " - " & strSize
rstAnotherProject.MoveNext
Wend
-----------------------------------------------------------------------



Is this what you were looking for or help in any way? If not i will try to get you the correct bit of information that you are looking for asap.

Thanks for the help!

CreganTur
06-16-2008, 10:44 AM
So the combo box is not populating with the FixtureType & FixtureSize information when you choose the "existing project" options... or try to retrieve data from an existing project? :think:

I'm guessing that there is a field on the same form as your combo box that the user has to fill out prior to hitting the enter key to move down to the combo box, and that this prior field will help determine what values fill the combo box.

If this is the case, then I would suggest not using the key up event. Instead I would use an After Update event on the field that decides what values are placed into the combo box. The After Update event is fired after the value of a textbox has been changed and focus is moved away from it. This would accomplish exactly the same thing as the key up event you mentioned in your first post.

If this does not answer your question, then please provide more information about what has to happen in order to fire off the code that is supposed to fill in the combo box.

DarkSprout
06-16-2008, 11:24 AM
Why Not:=

Private Sub tbDiffProjJobNum_KeyUp(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 13 ' Enter
KeyCode = 9
End Case
End Sub

seeking_help
06-16-2008, 11:32 AM
No the information will go correctly into the combo box on all 3 choices, but the "existing" is the only one that requires user input. I was just thinking that it would be more convenient to be able to hit the return key and have the drop down list from the combo box appear with the info instead of having to go back to your mouse to click the down arrow. I'm not sure if there was a way to just hit enter, have the list open(my problem), then continue typing to find the block you wish, then enter x2 to tab to the copy command button and then to do the copy command.
Currently when I hit return it will set the cursor to the combo box but will not populate it, which I don't understand because it should do that on the GotFocus event.
I do have an AfterUpdate event already, but is there something else that it needs for your idea to work?

------------------------------------
Private Sub Combo0_AfterUpdate()
If Form_frmPickFixture.Combo0.Value <> "" Then
Form_frmPickFixture.cmdCopyFrom.Enabled = True
End If
End Sub
------------------------------------

The only real reason I used the KeyUp event was because it appears that the enter key is not handled on the KeyPress event, and I am trying to get user friendly (for some users that are not as handy with computers as others but are good Engineers) GUI that can be smoothly navigated. That is where the tab comes into play with the problem of the drop down list not being populated until the arrow click :(

Thanks again and I will give more info/code as needed to help you try and help me! Hope this helps!

seeking_help
06-16-2008, 11:42 AM
DarkSprout
One minor error--End Case should be End Select, but that is still not accepting the return key for some reason.

I put the msgbox "hi" in there to check but it still gets skipped unless i put it outside the loop. So it must be something with the KeyCode or KeyAscii (depending on the event) correct? I am not understanding why it is not being accepted, everything is labeled correctly and there is no Default values set on the cmd buttons, and Key Preview is true (yes).

Thanks for the help

Carl A
06-16-2008, 11:54 AM
Set the focus to the combo box

Private Sub tbDiffProjJobNum_KeyUp(KeyCode As Integer, Shift As Integer)
If vbkey = 13 Then
Combo0.SetFocus
End If
End Sub

Private Sub Combo0_GotFocus()
'Routine to fill combo here
Me.Combo0.Dropdown
End Sub


HTH

seeking_help
06-16-2008, 12:02 PM
Carl A

Absolutely perfect!!!!!!
Exactly what I was hoping to accomplish. Now when I hit the return key it populates the box with my info. Was simply not setting the focus to the correct place, and the Me.Combo0.Dropdown (I would have never thought of that) worked perfectly.
Extreme thanks as this has been bugging me for as long as last wed.
Thank you all for the help!!
Best regards