Re: Need VBA Help to Append!
- From: "Chegu Tom" <noemail@xxxxxxxxx>
- Date: Thu, 16 Jul 2009 13:43:46 -0500
Option 1. I would use a different syntax. I don't recognize what you are
doing, it may be just fine. I think you need some single quotes and hash
marks to delimit your string and date fields. I assume (for this example)
that
textmployeeId is numeric, = 454678
txtemployeename is string = 'John Smith'
datDate is Date type = #05/05/2009#
also be sure to put a space after you commas.
Your Code---------------------
VALUES("&me.txtEmployeeID&","&me.cboEmployeeName&", _
"&me.datDate&","&me.intVacationUsed&","&me.intSickUsed&", _-----------------------------------------------
"&me.ckProperDoc&","&me.ckTardy&","&me.cboTimeTardy&", _
"&me.ckMissedPunch&","&me.ckOccurrence&, _
"&me.cboTypeOccurrence&","&me.txtOccurrenceValue&", _
"&me.cboNonOccurrence&","&me.txtAdditionalComments&")";
My suggestions
"Select " & me.txtemployeeid & ", '" & me.cboEmployeeName & "', #" &
me.datDate & "#, " etc etc
Notice single quotes around the employee name and Hash marks around the
date, no delimiters around employee Id (a numeric field)
One thing to do once you have written the code and get an error. Go the the
immediate mode in your VBA editor
and print strSQL then check to see that all of the values you entered are
set in the proper delimiters and the commas and spaces are all right
In this example = Select 454678, 'john smith', #05/05/2009#,
"GoBrowns!" <GoBrowns@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:41FE4DB1-8162-4028-B8D2-92A40C02E29A@xxxxxxxxxxxxxxxx
Hi;
I am trying to create a "submit" button that will append the form fields
to
a table. The user will click "submit", get a message box to make sure they
REALLY want to submit, then if they click yes the data will be submitted.
I am getting syntax errors in my code, and I can't figure out what is
wrong.
I wrote the code two different ways.....
Here it is.....
This part seems to work....
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 strLastChance As String
Dim strAppend As String
Dim strSQL As String
strLastChance = MsgBox( _
Prompt:="Are you sure you want to submit record?", _
Buttons:=vbYesNo + vbExclamation, _
Title:="Confirm Submission Decision")
If vbYes Then
Here is Option #1 for after my "if" line...
strSQL = "INSERT INTO tblAttendanceRecords(EmployeeID, EmployeeName,
Date," _
VacationTimeUsed, SickTimeUsed, ProperDocumentationFiled,
Tardy,
TardyTime, MissedPunch, _
Occurrence, OccurrenceDescription, OccurrenceValue,
NonOccurrenceDescription, _
AdditionalComments)VALUES("&me.txtEmployeeID&","&me.cboEmployeeName&", _
"&me.datDate&","&me.intVacationUsed&","&me.intSickUsed&", _
"&me.ckProperDoc&","&me.ckTardy&","&me.cboTimeTardy&", _
"&me.ckMissedPunch&","&me.ckOccurrence&, _
"&me.cboTypeOccurrence&","&me.txtOccurrenceValue&", _
"&me.cboNonOccurrence&","&me.txtAdditionalComments&")";
DBEngine(0)(0).Execute strSQL
And Option #2.....
strAppend = "INSERT INTO tblAttendanceRecords(txtEmployeeID as
EmployeeID," _
cboEmployeeName as EmployeeName, _
datDate as Date, _
intVacationUsed as VacationTimeUsed, _
intSickUsed as SickTimeUsed, _
ckProperDoc as ProperDocumentationFiled, _
ckTardy as Tardy, _
cboTimeTardy as TardyTime, _
ckMissedPunch as MissedPunch, _
ckOccurrence as OccurrenceDescription, _
cboTypeOccurrence as Occurrence, _
txtOccurrenceValue as OccurrenceValue, _
cboNonOccurrence as NonOccurrenceDescription, _
txtAdditionalComments as AdditionalComments)";
DoCmd.RunSQL strAppend
Will either of these options work??? If so, how do I fix one of them to
append the info???
So stumped... thanks for the help!!!!!!!
.
- Follow-Ups:
- Re: Need VBA Help to Append!
- From: GoBrowns!
- Re: Need VBA Help to Append!
- References:
- Need VBA Help to Append!
- From: GoBrowns!
- Need VBA Help to Append!
- Prev by Date: Re: Adding ALL to drp down list
- Next by Date: Before Update Event
- Previous by thread: Need VBA Help to Append!
- Next by thread: Re: Need VBA Help to Append!
- Index(es):