:banghead:I submitted this problem to the 'Forms' forum and received several responses. None of those suggestions worked. So, I'm appealing to the VBA code experts for assistance.
By clicking on a Access 2007 form's control (mkmybidder), I want the on-click vba code to:
1. Create a new folder (C_Name) obtained from the form's 'C_Name' field;
2. Copy the 'model' file (path is 'C:\MyBidder\model.xlsx') to the new 'C_Name' folder;
3. Next, automatically transfer the contents of named form fields to designated cell locations on the model.xlsx file, without destroying the structure & data on that file.
4. Then, save & rename the copied 'model' xlsx file to 'C_Name_Roofr.xlsx';
5. Finally, open the file for reviewing. (I know how to save it ha ha 8.1.
BTW: VBA code to 'mkdir', only, does not function on my computers (Win 8.1 or XP);
however, it does work using the DOS command 'mkdir'. Also, the ' Microsoft Excel Object Library' reference is marked. Not aware of other 'marks' that may be required.
Here is my code, incorporating my requirements into example code from JHB of 'forms':
Private Sub mkmybidder_Click()
Dim appExcel As Excel.Application
Dim lngLastDataRow As Long
MkDir (Me.Bidder)
FileCopy "C:\Access programmer\Client.xls", (Me.Bidder) & "\C_Name Roof.xlsx"
Set appExcel = CreateObject("Excel.Application")
With appExcel
.Visible = True
.UserControl = True
With .Workbooks.Open((Me.Bidder) & "\C_Name Roof.xlsx")
lngLastDataRow = .Worksheets("Sheet1").Cells.SpecialCells(xlCellTyp eLastCell).Row
.Worksheets("Sheet1").Range("I2" & CStr(lngLastDataRow + 1)) = Me.C_Name
.Worksheets("Sheet1").Range("I3" & CStr(lngLastDataRow + 1)) = Me.Address
.Worksheets("Sheet1").Range("I4" & CStr(lngLastDataRow + 1)) = Me.City
.Worksheets("Sheet1").Range("I5" & CStr(lngLastDataRow + 1)) = Me.Zip
.Worksheets("Sheet1").Range("I7" & CStr(lngLastDataRow + 1)) = Me.Address
.Worksheets("Sheet1").Range("I8" & CStr(lngLastDataRow + 1)) = Me.Phone_No
.Worksheets("Sheet1").Range("I9" & CStr(lngLastDataRow + 1)) = Me.Work_No
.Worksheets("Sheet1").Range("N2" & CStr(lngLastDataRow + 1)) = Me.Cust_Date
.Worksheets("Sheet1").Range("N4" & CStr(lngLastDataRow + 1)) = Me.Cust_No
End With
End With
appExcel.WindowState = xlMaximized
Set appExcel = Nothing
End Sub
Most likely, I've interpreted JHBs example incorrectly. Tnx in advance for caring to help me.
By clicking on a Access 2007 form's control (mkmybidder), I want the on-click vba code to:
1. Create a new folder (C_Name) obtained from the form's 'C_Name' field;
2. Copy the 'model' file (path is 'C:\MyBidder\model.xlsx') to the new 'C_Name' folder;
3. Next, automatically transfer the contents of named form fields to designated cell locations on the model.xlsx file, without destroying the structure & data on that file.
4. Then, save & rename the copied 'model' xlsx file to 'C_Name_Roofr.xlsx';
5. Finally, open the file for reviewing. (I know how to save it ha ha 8.1.
BTW: VBA code to 'mkdir', only, does not function on my computers (Win 8.1 or XP);
however, it does work using the DOS command 'mkdir'. Also, the ' Microsoft Excel Object Library' reference is marked. Not aware of other 'marks' that may be required.
Here is my code, incorporating my requirements into example code from JHB of 'forms':
Private Sub mkmybidder_Click()
Dim appExcel As Excel.Application
Dim lngLastDataRow As Long
MkDir (Me.Bidder)
FileCopy "C:\Access programmer\Client.xls", (Me.Bidder) & "\C_Name Roof.xlsx"
Set appExcel = CreateObject("Excel.Application")
With appExcel
.Visible = True
.UserControl = True
With .Workbooks.Open((Me.Bidder) & "\C_Name Roof.xlsx")
lngLastDataRow = .Worksheets("Sheet1").Cells.SpecialCells(xlCellTyp eLastCell).Row
.Worksheets("Sheet1").Range("I2" & CStr(lngLastDataRow + 1)) = Me.C_Name
.Worksheets("Sheet1").Range("I3" & CStr(lngLastDataRow + 1)) = Me.Address
.Worksheets("Sheet1").Range("I4" & CStr(lngLastDataRow + 1)) = Me.City
.Worksheets("Sheet1").Range("I5" & CStr(lngLastDataRow + 1)) = Me.Zip
.Worksheets("Sheet1").Range("I7" & CStr(lngLastDataRow + 1)) = Me.Address
.Worksheets("Sheet1").Range("I8" & CStr(lngLastDataRow + 1)) = Me.Phone_No
.Worksheets("Sheet1").Range("I9" & CStr(lngLastDataRow + 1)) = Me.Work_No
.Worksheets("Sheet1").Range("N2" & CStr(lngLastDataRow + 1)) = Me.Cust_Date
.Worksheets("Sheet1").Range("N4" & CStr(lngLastDataRow + 1)) = Me.Cust_No
End With
End With
appExcel.WindowState = xlMaximized
Set appExcel = Nothing
End Sub
Most likely, I've interpreted JHBs example incorrectly. Tnx in advance for caring to help me.