Here's one way to do this:
1) Create a table (name it tblTempImport) that can hold the imported data
from the EXCEL file (we'll use this as a temporary holding place for the
data).
2) Create a form that has a textbox and a command button on it.
3) Name the textbox txtDate and the button cmdImport.
4) Set format of the textbox to Short Date.
5) Use this programming code for your command button's Click event (Code
assumes that the name of the permanent table is tblPermanent, and assumes
that you have a fixed path and file name for the EXCEL file):
' START of code
Private Sub cmdImport_CLick()
Dim dbs As DAO.Database
Dim datDate As Date
Dim strSQL As String
Const strImport As String = "tblImportData"
' change tblPermanent to real name of permanent table
Const strTable As String = "tblPermanent"
' change string to actual path and file name of EXCEL file
Const strFile As String = "C:\MyFolder\EXCELFile.xls"
On Error GoTo Err_Msg
If Len(Me.txtDate.Value & "") = 0 Then
MsgBox "Enter a date!"
Else
Set dbs = CurrentDb()
strSQL = "DELETE * FROM tblImportData;"
dbs.Execute strSQL, dbFailOnError
' change True to False if the EXCEL file's spreadsheet
' DOES NOT have headers in first row
DoCmd.TransferSpreadsheet acImport,acSpreadsheetTypeExcel9, _
strImport, strFile, True
datDate = Me.txtDate.Value
strSQL = "INSERT INTO [" & strTable & "] " & _
"SELECT T.*, #" & Format(datDate, "mm\/dd\/yyyy") & _
"# FROM [" & strImport & "];"
dbs.Execute strSQL, dbFailOnError
End If
Exit_Code:
On Error Resume Next
dbs.Close
Set dbs = Nothing
Exit Sub
Err_Msg:
MsgBox "Error " & Err.Number & " has occurred: '" & Err.Description & "'."
Resume Exit_Code
End Sub
' END of code
Now, you can open this form, put the date in the textbox, and click the
button to import the data.
--
Ken Snell
<MS ACCESS MVP>
Tandy said:
Sorry! I didn't mean to be vague. Currently I'm in the beginning of
making
this database. So I have just been importing the data from an Excel file
directly into the Access table using the wizard. The Excel file
basically
has the two field names, EmployeeID and MonthlyHours, and then all the
information. I would love to have a form where the user just enters the
date, clicks a button and it's done. But I don't have any experience
with
importing and such. So any help will be greatly appreciated!!!
Tandy