Inbox issues

K

kharpe

I have a form with a button used to open a second form. The SQL code behind
the button opens an input box for user input of an "FCSI Number". When the
user enters a valid FCSI number, the second form opens correctly. There are
two instances during which I recieve an error. The first is if the user
cancels the input box, and the second is if no value is entered for the "FCSI
number"

Private Sub AddRemove_Click()
On Error GoTo Err_ADDRemove_Click

Dim DocName As String
Dim StCriteria As String

Dim stMsg As String
Dim stInput As String

DocName = "WPAddRemove"

stMsg = "Enter FCSI number"
'Prompt for input
stInput = InputBox(stMsg)
StCriteria = BuildCriteria("FCSI_ID", dbInteger, stInput)
StCriteria = StCriteria & "And " & "[Vessel_ID]=" & Me![Vessel_ID]
DoCmd.OpenForm DocName, , , StCriteria
Forms!WPAddRemove!WP_ID.DefaultValue = "" & Me![WP_Key] & ""

Exit_ADDRemove_Click:
Set rs = Nothing
Set qdf = Nothing
Set db = Nothing
Exit Sub

Err_ADDRemove_Click:
MsgBox Err.Description
Resume Exit_ADDRemove_Click

End Sub

The above is the code for the sub. If anyone can help me with capturing the
two errors it would be apreciated.
 
D

Douglas J. Steele

It's the same check for both errors:

Private Sub AddRemove_Click()
On Error GoTo Err_ADDRemove_Click

Dim DocName As String
Dim StCriteria As String

Dim stMsg As String
Dim stInput As String

DocName = "WPAddRemove"

stMsg = "Enter FCSI number"
'Prompt for input
stInput = InputBox(stMsg)
If Len(stInput) = 0 Then
MsgBox "You must spupply an FCSI number."
Else
StCriteria = BuildCriteria("FCSI_ID", dbInteger, stInput)
StCriteria = StCriteria & "And " & "[Vessel_ID]=" & Me![Vessel_ID]
DoCmd.OpenForm DocName, , , StCriteria
Forms!WPAddRemove!WP_ID.DefaultValue = "" & Me![WP_Key] & ""
End If

Exit_ADDRemove_Click:
Set rs = Nothing
Set qdf = Nothing
Set db = Nothing
Exit Sub

Err_ADDRemove_Click:
MsgBox Err.Description
Resume Exit_ADDRemove_Click

End Sub
 
K

kharpe

That helps. I want the input box to close when the cancel button is pressed,
but to re-open if no Value is entered, but the OK button is pressed. Is there
a method that I can differentiate between which oft the two buttons is
pressed on the input box?

Douglas J. Steele said:
It's the same check for both errors:

Private Sub AddRemove_Click()
On Error GoTo Err_ADDRemove_Click

Dim DocName As String
Dim StCriteria As String

Dim stMsg As String
Dim stInput As String

DocName = "WPAddRemove"

stMsg = "Enter FCSI number"
'Prompt for input
stInput = InputBox(stMsg)
If Len(stInput) = 0 Then
MsgBox "You must spupply an FCSI number."
Else
StCriteria = BuildCriteria("FCSI_ID", dbInteger, stInput)
StCriteria = StCriteria & "And " & "[Vessel_ID]=" & Me![Vessel_ID]
DoCmd.OpenForm DocName, , , StCriteria
Forms!WPAddRemove!WP_ID.DefaultValue = "" & Me![WP_Key] & ""
End If

Exit_ADDRemove_Click:
Set rs = Nothing
Set qdf = Nothing
Set db = Nothing
Exit Sub

Err_ADDRemove_Click:
MsgBox Err.Description
Resume Exit_ADDRemove_Click

End Sub




--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


kharpe said:
I have a form with a button used to open a second form. The SQL code behind
the button opens an input box for user input of an "FCSI Number". When the
user enters a valid FCSI number, the second form opens correctly. There
are
two instances during which I recieve an error. The first is if the user
cancels the input box, and the second is if no value is entered for the
"FCSI
number"

The above is the code for the sub. If anyone can help me with capturing
the
two errors it would be apreciated.
 
D

Douglas J. Steele

There's no way that I'm aware of to distinguish between the two actions.

What you can do is set a default value of 0. If they click OK, the input box
will return 0, if they click cancel, the input box will return a zero-length
string.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


kharpe said:
That helps. I want the input box to close when the cancel button is
pressed,
but to re-open if no Value is entered, but the OK button is pressed. Is
there
a method that I can differentiate between which oft the two buttons is
pressed on the input box?

Douglas J. Steele said:
It's the same check for both errors:

Private Sub AddRemove_Click()
On Error GoTo Err_ADDRemove_Click

Dim DocName As String
Dim StCriteria As String

Dim stMsg As String
Dim stInput As String

DocName = "WPAddRemove"

stMsg = "Enter FCSI number"
'Prompt for input
stInput = InputBox(stMsg)
If Len(stInput) = 0 Then
MsgBox "You must spupply an FCSI number."
Else
StCriteria = BuildCriteria("FCSI_ID", dbInteger, stInput)
StCriteria = StCriteria & "And " & "[Vessel_ID]=" & Me![Vessel_ID]
DoCmd.OpenForm DocName, , , StCriteria
Forms!WPAddRemove!WP_ID.DefaultValue = "" & Me![WP_Key] & ""
End If

Exit_ADDRemove_Click:
Set rs = Nothing
Set qdf = Nothing
Set db = Nothing
Exit Sub

Err_ADDRemove_Click:
MsgBox Err.Description
Resume Exit_ADDRemove_Click

End Sub




--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


kharpe said:
I have a form with a button used to open a second form. The SQL code
behind
the button opens an input box for user input of an "FCSI Number". When
the
user enters a valid FCSI number, the second form opens correctly.
There
are
two instances during which I recieve an error. The first is if the user
cancels the input box, and the second is if no value is entered for the
"FCSI
number"

The above is the code for the sub. If anyone can help me with capturing
the
two errors it would be apreciated.
 

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

Top