i am using Office 97.
Could you please give me the code to accomplish the following:
i need some programming help in Access and help creating a command button on an Excel template.
on an Access form, the user enters some data and then clicks a button called Email.
Then, an excel template opens and certain fields from the Access form are filled into the Excel template.
Then, the Excel template is named and saved with the name of a text box on the Access form.
Then, i need Excel to stay open. I would like a command button on Excel that when clicked, opens Outlook with the TO and SUBJECT filled in And i need the Excel document to be an attachment for that email (similar to clicking File, Send to, Mail Recipient in Excel).
i have some code that does part of what i need.
Function PopulateExcel() As String
Private Const XLT_LOCATION As String = "W:\Reports\Database\Request.xlt"
On Error GoTo Populate_Err
Dim db As Database
Dim qdf As QueryDef
Dim prm As Parameter
Dim rs As Recordset
Dim objXL As Object, objSheet As Object, objRange As Object
Dim strSaveAs As String, strRecord As String
Dim x As Integer, intRow As Integer
DoCmd.Hourglass True
Set db = CurrentDb()
' Open, and make visible the Excel Template (Request.xlt)
Set objXL = GetObject(XLT_LOCATION)
objXL.Application.Visible = True
objXL.Parent.Windows(1).Visible = True
' Open the recordset, and activate the sheet in the template
Set qdf = db.QueryDefs("qryRequest"
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rs = qdf.OpenRecordset(dbOpenSnapshot)
Set objSheet = objXL.Worksheets("TNSS"
objSheet.Activate
rs.MoveFirst
' Insert the data from the recordset into the worksheet
objXL.ActiveSheet.Cells(1, 5).Value = rs![Type]
objXL.ActiveSheet.Cells(3, 2).Value = rs![ProjectTitle]
' Set the save string, and save the spreadsheet. The file is saved with the project title as its name. (rs![ProjectTitle])
strSaveAs = "W:\Reports\TimingRequests\" & rs![ProjectTitle] & ".xls"
objXL.SaveCopyAs strSaveAs
PopulateExcel = strSaveAs
rs.Close
That opens the Excel template file and populates the fields in the template. It also save the Excel file in the correct folder and leaves Excel open. But, the excel file that is open and visible is the template file. I would like the newly named file to be the open that is open.
And, if the user currently had Excel open, the template doesn't open at all!!
Help please
thank you
ruth
Could you please give me the code to accomplish the following:
i need some programming help in Access and help creating a command button on an Excel template.
on an Access form, the user enters some data and then clicks a button called Email.
Then, an excel template opens and certain fields from the Access form are filled into the Excel template.
Then, the Excel template is named and saved with the name of a text box on the Access form.
Then, i need Excel to stay open. I would like a command button on Excel that when clicked, opens Outlook with the TO and SUBJECT filled in And i need the Excel document to be an attachment for that email (similar to clicking File, Send to, Mail Recipient in Excel).
i have some code that does part of what i need.
Function PopulateExcel() As String
Private Const XLT_LOCATION As String = "W:\Reports\Database\Request.xlt"
On Error GoTo Populate_Err
Dim db As Database
Dim qdf As QueryDef
Dim prm As Parameter
Dim rs As Recordset
Dim objXL As Object, objSheet As Object, objRange As Object
Dim strSaveAs As String, strRecord As String
Dim x As Integer, intRow As Integer
DoCmd.Hourglass True
Set db = CurrentDb()
' Open, and make visible the Excel Template (Request.xlt)
Set objXL = GetObject(XLT_LOCATION)
objXL.Application.Visible = True
objXL.Parent.Windows(1).Visible = True
' Open the recordset, and activate the sheet in the template
Set qdf = db.QueryDefs("qryRequest"
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rs = qdf.OpenRecordset(dbOpenSnapshot)
Set objSheet = objXL.Worksheets("TNSS"
objSheet.Activate
rs.MoveFirst
' Insert the data from the recordset into the worksheet
objXL.ActiveSheet.Cells(1, 5).Value = rs![Type]
objXL.ActiveSheet.Cells(3, 2).Value = rs![ProjectTitle]
' Set the save string, and save the spreadsheet. The file is saved with the project title as its name. (rs![ProjectTitle])
strSaveAs = "W:\Reports\TimingRequests\" & rs![ProjectTitle] & ".xls"
objXL.SaveCopyAs strSaveAs
PopulateExcel = strSaveAs
rs.Close
That opens the Excel template file and populates the fields in the template. It also save the Excel file in the correct folder and leaves Excel open. But, the excel file that is open and visible is the template file. I would like the newly named file to be the open that is open.
And, if the user currently had Excel open, the template doesn't open at all!!
Help please
thank you
ruth