A couple of questions:
I apologize for the long post. Any suggestions would be appreciated.
Thanks in advance,
Bernie
My first question is:
Why do I get multiple InputBoxes if I Loop through a procedure more than
once? For example, I put up an InputBox to allow the User to enter a value
to be included in a select statement. If they enter nothing, I capture that
and give them the opportunity to try again. If they accept the offer to try
again, the procedure will loop and create another instance of the InputBox.
I've tried to Unload it after each loop, but the syntax is all wrong. Here's
my code:
Private Sub DataSelect()
Dim intAnswer As Integer
Message = "Enter a Part Number" ' Set message prompt.
Title = "Part Number" ' Set title.
Default = "" ' Set default.
strSelect = InputBox(Message, Title, Default)
datData.RecordSource = "Select * FROM Parts WHERE PartNum Like '" & _
"*" & strSelect & "*" & "' ORDER BY PartNum"
datData.Refresh
lblCount.Caption = ""
Call RecordCountSelect
Do While strSelect = "" Or txtPartNum = ""
If MsgBox("You entered an incomplete or invalid Part Number: " _
& strSelect & vbCrLf & "Do you want to try again?", _
vbYesNo, "PartNumber?") = vbNo Then
datData.RecordSource = "Select * FROM Parts ORDER BY PartNum"
datData.Refresh
Exit Do
Exit Sub
Else
Call DataSelect
End If
Loop
End Sub
My second question is as follows:
If I attempt to "Save" a duplicate value in the PartNum field I get the
usual error message (this is normal). However, if I attempt to refresh (e.g.
datData.Refresh) in any procedure directly after trying to save, I get a
runtime error #444 "Method not applicable in this context". Note that I can
"Refresh" at all other times. Here's the code for the "Save" procedure.
Below that is the code for the Refresh.:
Private Sub DataSave()
If Len(txtPartNum.Text) > 0 Then
On Error GoTo DuplicateError
datData.UpdateRecord
cmdData(1).Enabled = False
cmdData(0).Caption = "&Add Record"
Call RecordCountX ' This call counts the records in the resultset
datData.Recordset.Bookmark = datData.Recordset.LastModified
Call ModeView ' This call sets the controls on the form
Exit Sub
End If
DuplicateError:
MsgBox "You have entered a duplicate Part Number.", _
vbOKOnly, "Duplicate part Number!"
datData.Recordset.Edit
datData.Recordset.CancelUpdate
datData.UpdateControls
Call ModeView ' This call sets the controls on the form
End Sub
Private Sub DataRefresh()
datData.RecordSource = "Select * from Parts ORDER BY PartNum"
datData.Refresh
datData.Recordset.MoveFirst
Call ModeView ' This call sets the controls on the form
Call RecordCountX ' This call counts the records in the resultset
End Sub