Setting focus after importing from excel

accessrookie2

Registered User.
Local time
Today, 03:11
Joined
Jul 23, 2009
Messages
16
Alright I need to set the focus to a textbox right after importing some data from an excel spreadsheet. It seems that after finishing the import, focus in no where on my form, furthermore even though the rest of the code runs it doesn't set the focus to the textbox. Is there a way to get the focus back to the textbox in the same sub? The end user will be using a scanner so the less interaction the better. Here is the code:

Dim WbPath As String
WbPath = filepath & filename & "_" & filerevision & ".xls"
Set xlApp = CreateObject("Excel.Application")
Set xlWb = xlApp.Workbooks.Open(WbPath)

'Get sheet count to loop through all the Excel sheets
SheetCount = xlWb.Worksheets.Count

'Loop through sheets
For lngCounter = 2 To SheetCount
Set xlWs = xlWb.Sheets(lngCounter)
'Set xlRng = xlWs.Range("A1")

'Get Address
GrabAddress = xlWs.Name & "!"
'Change address from Absolute to Relative reference
GrabAddress = Replace(GrabAddress, "$", "")

'Import data
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8, "ExcelTable", WbPath, False, GrabAddress

Set xlRng = Nothing
Set xlWs = Nothing
Next
xlWb.Close False
Set xlRng = Nothing
Set xlWb = Nothing
xlApp.Quit
Set xlApp = Nothing

zNumberBox.SetFocus

Like I said, the last line of the code runs but it does not move the focus. I believe the focus is still somewhere on the excel application and not in access but I'm not sure.

Thanks
 
Try changing this:

zNumberBox.SetFocus


to this

Me.zNumberBox.SetFocus
 
Thanks for the try but sadly still nothing. Focus is no where to be found, I can hit the tab key but it won't do anything. I'm thinking the users might have to do an extra click. Hopefully they won't miss the text box since it'll be on such a small screen.
 

Users who are viewing this thread

Back
Top Bottom