Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help!!!!!!!!!!!!!!! 1

Status
Not open for further replies.

jdwm2310

Technical User
Jul 26, 2001
396
US
Hi,

I have a form where users go to create help tickets, when they decide to close a ticket they would click on the save ticket. This button will save and close the ticket.
On the this form there are two textboxs "Question" and "Answers". I want that when the user decides to close the ticket that a "question" and "answer" be provided before closing and saving the ticket. How can I go about doing this? Below is the code I am using for the On Click Save button:

[tt]Private Sub Save_Click()
On Error GoTo Err_Save_Click
If MsgBox("Would like to close this ticket now?", vbYesNo + vbQuestion) = vbYes Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Me.Date_Closed = Now()
Me.TicketStatus = "Closed"
Me.Lock = True
DoCmd.Close acForm, "HelpDeskCalls", acSaveYes
DoCmd.OpenForm "TicketOption"
MsgBox "The ticket is saved", vbOKOnly + vbInformation = vbOK
Else
If MsgBox("Would like to close this ticket now?", vbYesNo + vbQuestion) = vbNo Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
If MsgBox("The status of this ticket is Pending, please return to this ticket later.", vbQuestion) = vbOK Then
Me.TicketStatus = "Pending"
DoCmd.Close acForm, "HelpDeskCalls", acSaveYes
DoCmd.OpenForm "TicketOption"
MsgBox "The ticket is saved", vbOKOnly + vbInformation = vbOK
End If
Exit_Save_Click:
Exit Sub
Err_Save_Click:
MsgBox Err.Description
Resume Exit_Save_Click
End If
End If
End Sub[/tt]
 
On Error GoTo Err_Save_Click

If MsgBox("Would you like to close this ticket now?", vbYesNo + vbQuestion) = vbYes Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Me.Date_Closed = Now()
Me.TicketStatus = "Closed"
Me.Lock = True
DoCmd.Close acForm, "HelpDeskCalls", acSaveYes
DoCmd.OpenForm "TicketOption"
Else
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
If MsgBox("The status of this ticket will be set to 'Pending', please return to this ticket later.", vbQuestion) = vbOK Then
Me.TicketStatus = "Pending"
DoCmd.Close acForm, "HelpDeskCalls", acSaveYes
DoCmd.OpenForm "TicketOption"
End If
End If

MsgBox "The ticket is saved", vbOKOnly + vbInformation = vbOK

Exit_Save_Click:
Exit Sub
Err_Save_Click:
MsgBox Err.Description
Resume Exit_Save_Click


If I'm understanding the above code, this is how I would write the code. Error Trapping should ALWAYS be at the end of the Sub/Function and out of the IF Statements otherwise, you would get an error.

HTH Roy McCafferty
aka BanditWk

Las Vegas, NV
roy@cccamerica.org
RLMBandit@aol.com (private)

"No need to send gifts, just send a smile."
 
Roy,

My question is how could I make my Answer field a required field only when the user decides to close the ticket.
 
I believe if you add a couple lines after your if statement you can accomplish what you are trying to do:

If MsgBox("Would you like to close this ticket now?", vbYesNo + vbQuestion) = vbYes Then
if not me.answerfld > "" then
msgbox "You must provide an answer before closing the ticket"
exit sub
end if

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
 
WMcGregor,

I added the line that you suggested but it still doesn't work....
[tt]Private Sub Save_Click()
On Error GoTo Err_Save_Click
If MsgBox("Would like to close this ticket now?", vbYesNo + vbQuestion) = vbYes Then
If Not Me.Answer_Comments > "" Then
MsgBox "You must provide an answer before closing the ticket"
Exit Sub
End If
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Me.Date_Closed = Now()
Me.TicketStatus = "Closed"
Me.Lock = True
DoCmd.Close acForm, "HelpDeskCalls", acSaveYes
DoCmd.OpenForm "TicketOption"
MsgBox "The ticket is saved", vbOKOnly + vbInformation = vbOK
Else
If MsgBox("Would like to close this ticket now?", vbYesNo + vbQuestion) = vbNo Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
If MsgBox("The status of this ticket is Pending, please return to this ticket later.", vbQuestion) = vbOK Then
Me.TicketStatus = "Pending"
DoCmd.Close acForm, "HelpDeskCalls", acSaveYes
DoCmd.OpenForm "TicketOption"
MsgBox "The ticket is saved", vbOKOnly + vbInformation = vbOK
End If
Exit_Save_Click:
Exit Sub
Err_Save_Click:
MsgBox Err.Description
Resume Exit_Save_Click
End If
End If
End Sub[/tt]
 
Try this,

Private Sub Save_Click()
On Error GoTo Err_Save_Click

If MsgBox("Would like to close this ticket now?", vbYesNo + vbQuestion) = vbYes Then

If IsNull(Me.Answer) Or IsNull(Me.Questions) Then

MsgBox "You must provide a question and an answer before closing the ticket"
GoTo Exit_Save_Click
End If

Me.Date_Closed = Now()
Me.TicketStatus = "Closed"
Me.Lock = True

DoCmd.Close acForm, "HelpDeskCalls", acSaveYes
DoCmd.OpenForm "TicketOption"
MsgBox "The ticket is saved", vbInformation

Else

MsgBox "The status of this ticket is Pending, please return to this ticket later.", vbInformation

Me.TicketStatus = "Pending"
DoCmd.Close acForm, "HelpDeskCalls", acSaveYes
DoCmd.OpenForm "TicketOption"
MsgBox "The ticket is saved", vbInformation
End If

Exit_Save_Click:
Exit Sub

Err_Save_Click:
MsgBox Err.Description
Resume Exit_Save_Click
End Sub

Cheers,

Pete
 
Pete,

It works, you are the greatest, thanks...Yipee!!!!!!!!!!!!!!! [pipe]



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top