R
Rhys Davies
I have linked our existing Access database to SQLand am running the tables
purely in SQL server 2008 having deleted the Acess tables and renamed the
linked tables to what the Access tables used to be called. However when i
try to run some code now it doesnt work. Clicking on the 'submit' button
normally inserts some information from the form screen into 'tblusers' and
then sends an email to an individual letting them know that the submission
has happened etc but now since linking to SQL tables it wont work. If I
comment out the recordset code then the email will be sent but obviously no
data will be inserted into 'tblusers' so it doesnt seem to like the code
concerning rstemp and where I attempt to open a recordset on 'tblusers'.
Does SQL require different code for the insertion to happen?
Any help would be greatly appreciated.
Thanks,
Rhys.
Private Sub submit_Click()
On Error GoTo Err_submit_Click
Me.Expense.Enabled = False
Dim rstemp As Recordset
Dim dls As Date
Dim straddress As String
Dim strbody As String
Dim strsubject As String
strsubject = "End of Month Submission from" & " " & loginname & "" & " " &
"for" & " " & Me.submitmonth & " " & Me.submityear
strbody = "Expenses:" & " " & "£" & Me.expenses & vbCrLf & "Available
Hours:" & " " & Me.totalhours & vbCrLf & "Hours Worked:" & " " &
Me.availablehours & vbCrLf & _
"TOIL @ Start of Month:" & " " & Me.TOIL & vbCrLf & "TOIL Accrued During
Month:" & " " & Me.toilaccduringmonth & vbCrLf & _
"New TOIL Figure:" & " " & Me.toilendofmonth
Set rstemp = CurrentDb.OpenRecordset("tblusers") 'SQL does not like this
section
rstemp.Index = "PrimaryKey"
rstemp.Seek "=", loginname
If rstemp.NoMatch Then
rstemp.AddNew
rstemp!loginname = loginname
rstemp!datelastsubmitted = currentdatesubmit
rstemp!datenextsubmit = datenextsubmit
rstemp!TOIL = toilendofmonth
rstemp.Update
DoCmd.SendObject , , acFormatHTML, "(e-mail address removed)", , , strsubject,
strbody, False, False
Me.currentdatesubmit = ""
Me.datenextsubmit = ""
Me.TOIL = ""
Me.availablehours = ""
Me.toilaccduringmonth = ""
Me.toilendofmonth = ""
Me.expenses = ""
Me.totalhours = ""
Me.datelastsubmitted = ""
Me.currentdatesubmit.Enabled = False
Me.datenextsubmit.Enabled = False
Me.TOIL.Enabled = False
Me.availablehours.Enabled = False
Me.toilaccduringmonth.Enabled = False
Me.toilendofmonth.Enabled = False
Me.expenses.Enabled = False
Me.totalhours.Enabled = False
Me.datelastsubmitted.Enabled = False
Me.closesubmit.SetFocus
Me.submit.Enabled = False
Else
If rstemp!datelastsubmitted < currentdatesubmit Then
rstemp.edit
rstemp!datelastsubmitted = currentdatesubmit
rstemp!datenextsubmit = datenextsubmit
rstemp!TOIL = toilendofmonth
rstemp.Update
DoCmd.SendObject , , acFormatHTML, "(e-mail address removed)", , , strsubject,
strbody, False, False
Me.currentdatesubmit = ""
Me.datenextsubmit = ""
Me.TOIL = ""
Me.availablehours = ""
Me.toilaccduringmonth = ""
Me.toilendofmonth = ""
Me.expenses = ""
Me.totalhours = ""
Me.datelastsubmitted = ""
Me.currentdatesubmit.Enabled = False
Me.datenextsubmit.Enabled = False
Me.TOIL.Enabled = False
Me.availablehours.Enabled = False
Me.toilaccduringmonth.Enabled = False
Me.toilendofmonth.Enabled = False
Me.expenses.Enabled = False
Me.totalhours.Enabled = False
Me.datelastsubmitted.Enabled = False
Me.closesubmit.SetFocus
Me.submit.Enabled = False
'Else
'response = MsgBox(("You cannot submit a month pior to the last
submission date."), vbOKOnly)
'Me.currentdatesubmit.SetFocus
End If
End If
rstemp.close
Set rstemp = Nothing
Exit_submit_Click:
Exit Sub
Err_submit_Click:
'MsgBox Err.Description
Resume Exit_submit_Click
End Sub
purely in SQL server 2008 having deleted the Acess tables and renamed the
linked tables to what the Access tables used to be called. However when i
try to run some code now it doesnt work. Clicking on the 'submit' button
normally inserts some information from the form screen into 'tblusers' and
then sends an email to an individual letting them know that the submission
has happened etc but now since linking to SQL tables it wont work. If I
comment out the recordset code then the email will be sent but obviously no
data will be inserted into 'tblusers' so it doesnt seem to like the code
concerning rstemp and where I attempt to open a recordset on 'tblusers'.
Does SQL require different code for the insertion to happen?
Any help would be greatly appreciated.
Thanks,
Rhys.
Private Sub submit_Click()
On Error GoTo Err_submit_Click
Me.Expense.Enabled = False
Dim rstemp As Recordset
Dim dls As Date
Dim straddress As String
Dim strbody As String
Dim strsubject As String
strsubject = "End of Month Submission from" & " " & loginname & "" & " " &
"for" & " " & Me.submitmonth & " " & Me.submityear
strbody = "Expenses:" & " " & "£" & Me.expenses & vbCrLf & "Available
Hours:" & " " & Me.totalhours & vbCrLf & "Hours Worked:" & " " &
Me.availablehours & vbCrLf & _
"TOIL @ Start of Month:" & " " & Me.TOIL & vbCrLf & "TOIL Accrued During
Month:" & " " & Me.toilaccduringmonth & vbCrLf & _
"New TOIL Figure:" & " " & Me.toilendofmonth
Set rstemp = CurrentDb.OpenRecordset("tblusers") 'SQL does not like this
section
rstemp.Index = "PrimaryKey"
rstemp.Seek "=", loginname
If rstemp.NoMatch Then
rstemp.AddNew
rstemp!loginname = loginname
rstemp!datelastsubmitted = currentdatesubmit
rstemp!datenextsubmit = datenextsubmit
rstemp!TOIL = toilendofmonth
rstemp.Update
DoCmd.SendObject , , acFormatHTML, "(e-mail address removed)", , , strsubject,
strbody, False, False
Me.currentdatesubmit = ""
Me.datenextsubmit = ""
Me.TOIL = ""
Me.availablehours = ""
Me.toilaccduringmonth = ""
Me.toilendofmonth = ""
Me.expenses = ""
Me.totalhours = ""
Me.datelastsubmitted = ""
Me.currentdatesubmit.Enabled = False
Me.datenextsubmit.Enabled = False
Me.TOIL.Enabled = False
Me.availablehours.Enabled = False
Me.toilaccduringmonth.Enabled = False
Me.toilendofmonth.Enabled = False
Me.expenses.Enabled = False
Me.totalhours.Enabled = False
Me.datelastsubmitted.Enabled = False
Me.closesubmit.SetFocus
Me.submit.Enabled = False
Else
If rstemp!datelastsubmitted < currentdatesubmit Then
rstemp.edit
rstemp!datelastsubmitted = currentdatesubmit
rstemp!datenextsubmit = datenextsubmit
rstemp!TOIL = toilendofmonth
rstemp.Update
DoCmd.SendObject , , acFormatHTML, "(e-mail address removed)", , , strsubject,
strbody, False, False
Me.currentdatesubmit = ""
Me.datenextsubmit = ""
Me.TOIL = ""
Me.availablehours = ""
Me.toilaccduringmonth = ""
Me.toilendofmonth = ""
Me.expenses = ""
Me.totalhours = ""
Me.datelastsubmitted = ""
Me.currentdatesubmit.Enabled = False
Me.datenextsubmit.Enabled = False
Me.TOIL.Enabled = False
Me.availablehours.Enabled = False
Me.toilaccduringmonth.Enabled = False
Me.toilendofmonth.Enabled = False
Me.expenses.Enabled = False
Me.totalhours.Enabled = False
Me.datelastsubmitted.Enabled = False
Me.closesubmit.SetFocus
Me.submit.Enabled = False
'Else
'response = MsgBox(("You cannot submit a month pior to the last
submission date."), vbOKOnly)
'Me.currentdatesubmit.SetFocus
End If
End If
rstemp.close
Set rstemp = Nothing
Exit_submit_Click:
Exit Sub
Err_submit_Click:
'MsgBox Err.Description
Resume Exit_submit_Click
End Sub