Date Variable Won't Populate Date Field

  • Thread starter kobi via AccessMonster.com
  • Start date
K

kobi via AccessMonster.com

I have a front end built as an ADP for a SQL backend. One button on a form
is intended to append another record to a table after entry and everything
works fine except the date field is populating 0 which shows as 1/1/1900. I
am missing something and have gone over it and over it for days and am not
seeing it. Can anyone please help? This is the code for the button.....

Private Sub Command0_Click()

Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim sql, sql1, sql2, sqlWhere, sqlUpdate As String
Dim frm, frmAN As Form
Dim rst As ADODB.Recordset
Dim CoNo, RefNo, Line As Integer
Dim sccEmp, src, mthd, summ, scci As String
Dim AppDate

Set cnn = CurrentProject.Connection
Set cmd = New ADODB.Command
Set rst = New ADODB.Recordset
Set frmAN = Forms!AddNew_Frm

CoNo = frmAN!HRCo
RefNo = frmAN!HRRef
src = frmAN!Source
summ = "Record of original entry to add a referral source record into the
contact log"
scci = "N"
Line = 1

'Define Date Field
If Not IsNull(frmAN!ApplicationDate) And frmAN!ApplicationDate <> 0 Then
AppDate = DateValue(frmAN!ApplicationDate)
ElseIf Not IsNull(frmAN!LastContactDate) And frmAN!LastContactDate <> 0
Then
AppDate = DateValue(frmAN!LastContactDate)
Else
AppDate = DateValue(Date)
End If

'Define SCC Employee field
If Not IsNull(Forms!Main_Frm!MeName) Then
sccEmp = Forms!Main_Frm!MeName
Else
sccEmp = InputBox("Enter your name here", "Record Entering Employee")
End If

'Define method of contact for those that are known by the status code
If frmAN!Status Like "Call-In" Then
mthd = "Phone"
ElseIf frmAN!Status Like "Applicant" Then
mthd = "Application"
Else
mthd = InputBox("Enter the method of contact that prompted this new
record entry? (ie E-Mail, Walk-In, Mail, etc.", "Method of Contact")
End If

sqlWhere = "SELECT * FROM [HRRM] WHERE udSecurity = 1 And HRCo=" & CoNo & "
And HRRef=" & RefNo

If IsNull(frmAN!HRRef) Then
DoCmd.Close
ElseIf IsNull(frmAN!HRCo) Then
DoCmd.Close
ElseIf IsNull(frmAN!Status) Then
MsgBox "The Status field is a required input that must be filled in
for you to proceed any further. Please choose a status from the available
list.", vbOKOnly, "Required Field Left Blank"
frmAN!Status.SetFocus
ElseIf IsNull(frmAN!Source) Then
MsgBox "Referral Source is a required field that must be filled in
for you to proceed any further. Please choose a referral source.", vbOKOnly,
"Required Field Left Blank"
frmAN!Source.SetFocus
ElseIf IsNull(frmAN!ApplicationDate) And Not IsNull(frmAN!LastContactDate)
Then


Else
cnn.BeginTrans
sql = "INSERT INTO udContactLogs (HRCo,HRRef,Number) VALUES (" &
CoNo & " , " & RefNo & " , " & Line & ")"
sqlUpdate = "UPDATE udContactLogs Set [Date]=" & AppDate & ",
Contact='" & sccEmp & "', NotesSumm='" & summ & "', Source='" & src & "',
Method='" & mthd & "', sccInitiated='" & scci & "' WHERE HRCo=" & Me!HRCo & "
And HRRef=" & Me!HRRef & " And Number = 1"
cnn.Execute sql
cnn.Execute sqlUpdate
DoCmd.GoToRecord , , acNewRec
cnn.Execute "DELETE FROM HREH WHERE [Type] = 'P'"
cnn.CommitTrans

If MsgBox("Would you like to enter additional application information
at this time?", vbYesNo, "Verification") = vbYes Then
'Open Results form if it's not opened
If CurrentProject.AllForms("Results_Frm").IsLoaded = False
Then
DoCmd.OpenForm "Results_Frm"
End If
Set frm = Forms!Results_Frm
rst.CursorLocation = adUseClient
rst.Open sqlWhere, cnn, adOpenDynamic, adLockOptimistic,
adCmdText
Set frm.Recordset = rst
DoCmd.Close acForm, "AddNew_Frm"
frm.SetFocus
Else
DoCmd.Close acForm, "AddNew_Frm"
End If

'Reset objects as necessary
Set frm = Nothing
Set frmAN = Nothing
Set rst = Nothing
Set cnn = Nothing

End If

End Sub
 

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