accessrookie2
Registered User.
- Local time
- Today, 12:43
- 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
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