InputBox Question/Error Handling

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I built a little automated survey tool with normalized tables to hold
questions divided up by department etc. For each department being surveyed I
have a command button that activates the the following on it's OnClick Event:

Dim Answer As String
Dim MyQ As String
Dim CurDept As String
Dim Acct
Set Acct = New ADODB.Recordset

Acct.Open "Accounting", CurrentProject.Connection, adOpenStatic

Do Until Acct.EOF

Me.AcctQID = Acct![Q_ID]

MyQ = Acct![Question]

CurDept = Acct![Department_Name]

If Acct![CommentOnly] = False Then

Answer = InputBox("On a scale of 1 to 5, with 5 being the best," & vbCrLf &
vbCrLf & "Please rate your opinion of the following:" & vbCrLf & vbCrLf &
MyQ, "Rate The Level Of Service for" & " " & CurDept)

MyInput.Value = [Answer]
AcctQID.Value = [QID]

[Comment] = InputBox("Please add any comments you would like to make
concerning:" & " " & vbCrLf & vbCrLf & MyQ, "Add A Comment About" & " " &
CurDept)

Else

[Comment] = InputBox("Please add any comments you would like to make
concerning:" & " " & vbCrLf & vbCrLf & MyQ, "Add A Comment About" & " " &
CurDept)

End If

DoCmd.Save

Acct.MoveNext

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

DoCmd.GoToRecord , , acNewRec

Loop


I have two questions, but am open to any other suggestions as I am still
very new at all this.
1. What do I need to add so that if the cancel button is hit on the inputbox
it stops the routine altogether rather than just moves on to the next
record/question?

2. I don't understand what happens with error handling at all. What do I
need to add?


Thanks in advance, all comments/assistance appreciated.
 
Hi Jeff,

The InputBox function returns User input as string. If the user clicks
Cancel, it returns a zero-length string. Hence, you can test it like:

If Answer <> "" Then
MyInput.Value = Answer
Else
Exit Sub 'Or whatever you want to do
End If
 

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

Back
Top