VBA to Append Form Fields Into Table?

G

GoBrowns!

I am trying to write code that will append a newly created record from my
form into a table. Several of the fields in my form are not tied to anything
(no table/query behind them) and some are. Here is what I wrote, I am pretty
sure I am way off base:

Private Sub cmdSubmit_Click()
'Asks user one more time if they are sure they want to submit,
'then appends form data to table and clears form.
Dim strAppend As String
strAppend = "INSERT INTO tblAttendanceRecords(txtEmployeeID as
EmployeeID, _
cboEmployeeName as EmployeeName, _
datDate as Date, _
txtVacationUsed as VacationTimeUsed, _
txtSickUsed as SickTimeUsed, _
ckProperDoc as ProperDocumentationFiled, _
ckTardy as Tardy, _
cboTimeTardy as TardyTime, _
ckMissedPunch as MissedPunch, _
ckOccurrence as Occurrence, _
cboTypeOccurrence as Occurrence, _
txtOccurrenceValue as OccurrenceValue, _
cboNonOccurrence as NonOccurrenceDescription, _
txtAdditionalComments as AdditionalComments)";

DoCmd.RunSQL strAppend

I think I have my SQL and VBA mixed up? Who knows, I am so confused.

Ideally, I would like this "on click" operation to also clear the form once
the information has been append to the table.

Are these things even possible? Please help!

Thanks!
 
P

PieterLinden via AccessMonster.com

GoBrowns! said:
I am trying to write code that will append a newly created record from my
form into a table. Several of the fields in my form are not tied to anything
(no table/query behind them) and some are. Here is what I wrote, I am pretty
sure I am way off base:

Private Sub cmdSubmit_Click()
'Asks user one more time if they are sure they want to submit,
'then appends form data to table and clears form.
Dim strAppend As String
strAppend = "INSERT INTO tblAttendanceRecords(txtEmployeeID as
EmployeeID, _
cboEmployeeName as EmployeeName, _
datDate as Date, _
txtVacationUsed as VacationTimeUsed, _
txtSickUsed as SickTimeUsed, _
ckProperDoc as ProperDocumentationFiled, _
ckTardy as Tardy, _
cboTimeTardy as TardyTime, _
ckMissedPunch as MissedPunch, _
ckOccurrence as Occurrence, _
cboTypeOccurrence as Occurrence, _
txtOccurrenceValue as OccurrenceValue, _
cboNonOccurrence as NonOccurrenceDescription, _
txtAdditionalComments as AdditionalComments)";

DoCmd.RunSQL strAppend

I think I have my SQL and VBA mixed up? Who knows, I am so confused.

Ideally, I would like this "on click" operation to also clear the form once
the information has been append to the table.

Are these things even possible? Please help!

Thanks!

Why not just use a form and set the DataEntry property to True?

If you absolutely insist on building your own SQL statement, it's...

"INSERT INTO MyTable(field1, field2, field3....) VALUES (" & me.control1 & ",
" & me.control2 & ... ")"

dbengine(0)(0).Execute strSQL
 
G

GoBrowns!

I want to do whatever is easiest. Do I reset the property in my current form?
How does that work??

Thanks!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top