I am trying to get insert the value of a cell into a database table but when I enter a line of code in the SQL insert parameter such as the line EmpName is set equal to I get an error. How can I get the value of the cell to go into the table and not what I have named the field.
Sub AppendFile()
Dim db1 As Database
Dim rstEmployees As DAO.Recordset
Dim EmpName As String
EmpName = Range("EMPLOYEE_NAME"
.Value
Set db1 = OpenDatabase("C:\Documents and Settings\dmitchell\My Documents\Employee Time.mdb"
Set rstEmployees = db1.OpenRecordset("EmployeeTime", dbOpenDynaset)
db1.Execute "INSERT INTO EmployeeTime " _
& "(EMPLOYEE_NAME) VALUES " _
& "('[EmpName]');"
db1.Close
'rstEmployees.Update
'.AddNew
'rstEmployees.Fields("Last Name"
= EmpName
Sub AppendFile()
Dim db1 As Database
Dim rstEmployees As DAO.Recordset
Dim EmpName As String
EmpName = Range("EMPLOYEE_NAME"
Set db1 = OpenDatabase("C:\Documents and Settings\dmitchell\My Documents\Employee Time.mdb"
Set rstEmployees = db1.OpenRecordset("EmployeeTime", dbOpenDynaset)
db1.Execute "INSERT INTO EmployeeTime " _
& "(EMPLOYEE_NAME) VALUES " _
& "('[EmpName]');"
db1.Close
'rstEmployees.Update
'.AddNew
'rstEmployees.Fields("Last Name"