Can this be done in Access -
07-29-2003
, 01:01 PM
Hello
Hello
I have an excel spreadsheet that that will be named different each
time. What I need to do is be able to open the file in free file and
have the data populate text boxes on 3 forms. I may be able to squeeze
al the boxes on to 1 or 2 forms if need be (Hopefully) I need to
populate the textboxes so I can update the database after I verify
that all the fields have the correct info in them. Can this be done?
Thanks Bob
Dim ExApp As Object
Dim WkBk As Object
Dim WkSht As Object
Dim tmpSheet As Object
'Set myexcel = CreateObject("Excel.Application")
Set ExApp = CreateObject("Excel.Application") 'Creates new instance
of Excel
strFile = ExApp.GetOpenFilename 'Opens dialog box so user can
pick file to open
Set WkBk = ExApp.Workbooks
WkBk.Open strFile 'Opens chosen file
Set WkSht = ExApp.ActiveSheet 'Selects the active (topmost)
worksheet
'On Form1
txtAdd.Text = WkSht.Cells(7, 3) 'Puts the cell value into the
text box
txtAdd2.Text = WkSht.Cells(8, 3)
txtAdd3.Text = WkSht.Cells(9, 3)
txtCity.Text = WkSht.Cells(10, 3)
txtContact.Text = WkSht.Cells(11, 3)
txtCustomer.Text = WkSht.Cells(6, 3)
txtDate.Text = WkSht.Cells(2, 5)
txtPhone.Text = WkSht.Cells(11, 8)
txtShipper.Text = WkSht.Cells(5, 3)
txtState.Text = WkSht.Cells(10, 6)
txtTech.Text = WkSht.Cells(2, 8)
txtZip.Text = WkSht.Cells(10, 8)
'On Form2
txtCams.Text = WkSht.Cells(17, 3)
txtCPU.Text = WkSht.Cells(19, 3)
txtIP.Text = WkSht.Cells(18, 3)
txtLic.Text = WkSht.Cells(18, 8)
txtMail.Text = WkSht.Cells(17, 8)
txtModem.Text = WkSht.Cells(16, 8)
txtOS.Text = WkSht.Cells(16, 3)
txtSoftWare.Text = WkSht.Cells(15, 3)
txtVer.Text = WkSht.Cells(15, 7)
'On Form3
txtAddPtr.Text = WkSht.Cells(29, 4)
txtAddPtr1.Text = WkSht.Cells(29, 6)
txtAddPtr2.Text = WkSht.Cells(29, 8)
txtKey.Text = WkSht.Cells(26, 4)
txtKey1.Text = WkSht.Cells(26, 6)
txtKey2.Text = WkSht.Cells(26, 8)
txtMon.Text = WkSht.Cells(25, 4)
txtMon1.Text = WkSht.Cells(25, 6)
txtMon2.Text = WkSht.Cells(25, 8)
txtMse.Text = WkSht.Cells(27, 4)
txtMse1.Text = WkSht.Cells(27, 6)
txtMse2.Text = WkSht.Cells(27, 8)
txtOther.Text = WkSht.Cells(31, 4)
txtOther1.Text = WkSht.Cells(31, 6)
txtOther2.Text = WkSht.Cells(31, 8)
txtRpt.Text = WkSht.Cells(28, 4)
txtRpt1.Text = WkSht.Cells(28, 6)
txtRpt2.Text = WkSht.Cells(28, 8)
txtScale.Text = WkSht.Cells(30, 4)
txtScale1.Text = WkSht.Cells(30, 6)
txtScale2.Text = WkSht.Cells(30, 8)
txtSysUnit.Text = WkSht.Cells(24, 4)
txtSysUnit1.Text = WkSht.Cells(24, 6)
txtSysUnit2.Text = WkSht.Cells(24, 8)
ExApp.Workbooks.Close
Set ExApp = Nothing
Set WkBk = Nothing
Set WkSht = Nothing |