Hi,
I have a Access 2007 form with 2 Subforms. On the main form I have a button that executes an event procedure. In this procedure I open an excel application + workbook and write some form values into the excel.
The code opens the excel and the workbook and even writes the values but when I want to execute the button an other time it seems as if my form values have vansihed. Although the values are still in the form, VB cant get hold of the variables like recordsets etc.
What can that be?I suspect it has anything to do with how I open Excel:
I would appreciate very much if anyone can point me into a direction. Thank you very much in advance.
UPDATE: I dont know if this helps: If I click with the mouse into several controls in all the subforms The VBA code can access the values again.
regards
Nic
I have a Access 2007 form with 2 Subforms. On the main form I have a button that executes an event procedure. In this procedure I open an excel application + workbook and write some form values into the excel.
The code opens the excel and the workbook and even writes the values but when I want to execute the button an other time it seems as if my form values have vansihed. Although the values are still in the form, VB cant get hold of the variables like recordsets etc.
What can that be?I suspect it has anything to do with how I open Excel:
Code:
Set xlWB = GetObject(workBookName)
If IsNull(xlApp) Then
'open new
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWB = xlApp.Workbooks.Open(workBookName, , False)
xlWB.Worksheets(workSheetName).Activate
Else
'Activate the existing
xlWB.Application.Visible = True
xlWB.Parent.Windows(1).Visible = True
xlWB.Activate
xlWB.Worksheets(workSheetName).Activate
xlWB.Worksheets(workSheetName).Range("A4").Value = "It works!!"
Set xlApp = Nothing
End If
UPDATE: I dont know if this helps: If I click with the mouse into several controls in all the subforms The VBA code can access the values again.
regards
Nic
Last edited: