mpearce
10-15-2009, 11:16 AM
I developed a survey application for my companies helpdesk team. heres the schema:
TBL_survey
ticketnumber(pk)
FullName
q1Answe
q2Answer
q3Answer
q4Answer
comments
i am using a select case to figure out whether or not the user has submitted a survey previously for a given ticket. but for some reason regardless of whether or not a survey exists for a ticket the code doesnt let the user know that they have already submitted once. the code would run like it is a new entry. of course the record isnt written to the table due to the primary key, but i would like to let the user know there is already an entry for that ticket.
heres the code:
Sub writeToTable(ByVal previous_submission As Integer, ByVal areyousure As Integer, _
ByVal ticketnumber As String, ByVal fullname As String, _
ByVal finalanswer As String, ByVal finalanswer2 As String, _
ByVal finalanswer3 As String, ByVal finalanswer4 As String, _
ByVal comments As String)
areyousure = MsgBox("You are about to submit the following information:" & vbCrLf & vbCrLf & _
"Ticket Number: " & ticketnumber & vbCrLf & _
"Full Name: " & fullname & vbCrLf & vbCrLf & _
"Question 1 Response: " & finalanswer & vbCrLf & _
"Question 2 Response: " & finalanswer2 & vbCrLf & _
"Question 3 Response: " & finalanswer3 & vbCrLf & _
"Question 4 Response: " & finalanswer4 & vbCrLf & vbCrLf & _
"Comments: " & comments, vbYesNo, "Are you sure?")
If areyousure = 6 Then
previous_submission = DCount("ticketnumber", "surveyresponse", "ticketnumber = '" & [ticketnumber] & "'")
MsgBox "ticket number: " & ticketnumber 'just for testing
MsgBox "previous_submission: " & previous_submission 'just for testing
Select Case previous_submissiion
Case Is = 1
MsgBox "There is already a survey submitted for this ticket. Thank you for your submission", _
vbCritical, "You have already submitted once"
Case Is = 0
MsgBox "process complete"
'CurrentDb.Execute "insert into SurveyResponse(ticketnumber,fullname,q1answer,q2answer," & _
"q3answer,q4answer, comments) " & _
"values('" & [ticketnumber] & "', '" & [fullname] & "', '" & _
[finalanswer] & "', '" & [finalanswer2] & "', '" & [finalanswer3] & "', '" & _
[finalanswer4] & "', '" & [comments] & "')"
End Select
ElseIf areyousure = 7 Then
Exit Sub
End If
End Sub
any help is appreciated.
16-Oct-09: Edited by geekgirlau. Reason: insert line breaks
TBL_survey
ticketnumber(pk)
FullName
q1Answe
q2Answer
q3Answer
q4Answer
comments
i am using a select case to figure out whether or not the user has submitted a survey previously for a given ticket. but for some reason regardless of whether or not a survey exists for a ticket the code doesnt let the user know that they have already submitted once. the code would run like it is a new entry. of course the record isnt written to the table due to the primary key, but i would like to let the user know there is already an entry for that ticket.
heres the code:
Sub writeToTable(ByVal previous_submission As Integer, ByVal areyousure As Integer, _
ByVal ticketnumber As String, ByVal fullname As String, _
ByVal finalanswer As String, ByVal finalanswer2 As String, _
ByVal finalanswer3 As String, ByVal finalanswer4 As String, _
ByVal comments As String)
areyousure = MsgBox("You are about to submit the following information:" & vbCrLf & vbCrLf & _
"Ticket Number: " & ticketnumber & vbCrLf & _
"Full Name: " & fullname & vbCrLf & vbCrLf & _
"Question 1 Response: " & finalanswer & vbCrLf & _
"Question 2 Response: " & finalanswer2 & vbCrLf & _
"Question 3 Response: " & finalanswer3 & vbCrLf & _
"Question 4 Response: " & finalanswer4 & vbCrLf & vbCrLf & _
"Comments: " & comments, vbYesNo, "Are you sure?")
If areyousure = 6 Then
previous_submission = DCount("ticketnumber", "surveyresponse", "ticketnumber = '" & [ticketnumber] & "'")
MsgBox "ticket number: " & ticketnumber 'just for testing
MsgBox "previous_submission: " & previous_submission 'just for testing
Select Case previous_submissiion
Case Is = 1
MsgBox "There is already a survey submitted for this ticket. Thank you for your submission", _
vbCritical, "You have already submitted once"
Case Is = 0
MsgBox "process complete"
'CurrentDb.Execute "insert into SurveyResponse(ticketnumber,fullname,q1answer,q2answer," & _
"q3answer,q4answer, comments) " & _
"values('" & [ticketnumber] & "', '" & [fullname] & "', '" & _
[finalanswer] & "', '" & [finalanswer2] & "', '" & [finalanswer3] & "', '" & _
[finalanswer4] & "', '" & [comments] & "')"
End Select
ElseIf areyousure = 7 Then
Exit Sub
End If
End Sub
any help is appreciated.
16-Oct-09: Edited by geekgirlau. Reason: insert line breaks