Vb code working one time

J

Jon

Hi,
I have a form for adding data to a table. In this form , there is a command
button for adding those data and it has the following code:
Private Sub Command22_Click()
On Error GoTo Err_Command22_Click
If IsNull(Me.Combo28) = True Then
MsgBox "You Must Select a S.O.Processor First.", vbCritical, "No Processor
Selected..."
Me.Combo28.SetFocus

ElseIf IsNull(Me.CONTRACT_NO) = True Then
MsgBox "You Must Input a Contract No. First.", vbCritical, "No Contract
No. Input..."
Me.CONTRACT_NO.SetFocus
ElseIf IsNull(Me.CONTRACTOR) = True Then
MsgBox "You Must Input Contractor First.", vbCritical, "No Contractor
Input..."
Me.CONTRACTOR.SetFocus
ElseIf IsNull(Me.Combo33) = True Then
MsgBox "You Must Select a Proponent First.", vbCritical, "No Proponent
Selected..."
Me.Combo33.SetFocus
ElseIf IsNull(Me.Combo30) = True Then
MsgBox "You Must Select a Advisor First.", vbCritical, "No Advisor
Selected..."
Me.Combo30.SetFocus
ElseIf IsNull(Me.TITLE_OF_CONTRACT) = True Then
MsgBox "You Must Input a Title of Contract First.", vbCritical, "No
Contract Title Input..."
Me.TITLE_OF_CONTRACT.SetFocus
ElseIf IsNull(Me.EXPIRY) = True Then
MsgBox "You Must Input an Expiry date First.", vbCritical, "No Expiry
date Input..."
Me.EXPIRY.SetFocus


Else
DoCmd.GoToRecord , , acNewRec
End If

Exit Sub
Exit_Command22_Click:
Exit Sub

Err_Command22_Click:
MsgBox Err.Description
Resume Exit_Command22_Click

End Sub

The code is working , but it works one time, after that, the code does not
work, because it is not asking the user about the combo box. It works with
text box only. Can any body tell me how to correct it?
 
D

Dirk Goldgar

Jon said:
Hi,
I have a form for adding data to a table. In this form , there is a
command
button for adding those data and it has the following code:
Private Sub Command22_Click()
On Error GoTo Err_Command22_Click
If IsNull(Me.Combo28) = True Then
MsgBox "You Must Select a S.O.Processor First.", vbCritical, "No Processor
Selected..."
Me.Combo28.SetFocus

ElseIf IsNull(Me.CONTRACT_NO) = True Then
MsgBox "You Must Input a Contract No. First.", vbCritical, "No Contract
No. Input..."
Me.CONTRACT_NO.SetFocus
ElseIf IsNull(Me.CONTRACTOR) = True Then
MsgBox "You Must Input Contractor First.", vbCritical, "No Contractor
Input..."
Me.CONTRACTOR.SetFocus
ElseIf IsNull(Me.Combo33) = True Then
MsgBox "You Must Select a Proponent First.", vbCritical, "No Proponent
Selected..."
Me.Combo33.SetFocus
ElseIf IsNull(Me.Combo30) = True Then
MsgBox "You Must Select a Advisor First.", vbCritical, "No Advisor
Selected..."
Me.Combo30.SetFocus
ElseIf IsNull(Me.TITLE_OF_CONTRACT) = True Then
MsgBox "You Must Input a Title of Contract First.", vbCritical, "No
Contract Title Input..."
Me.TITLE_OF_CONTRACT.SetFocus
ElseIf IsNull(Me.EXPIRY) = True Then
MsgBox "You Must Input an Expiry date First.", vbCritical, "No Expiry
date Input..."
Me.EXPIRY.SetFocus


Else
DoCmd.GoToRecord , , acNewRec
End If

Exit Sub
Exit_Command22_Click:
Exit Sub

Err_Command22_Click:
MsgBox Err.Description
Resume Exit_Command22_Click

End Sub

The code is working , but it works one time, after that, the code does not
work, because it is not asking the user about the combo box. It works with
text box only. Can any body tell me how to correct it?


Which combo box, Combo28, Combo33, or Combo30? Are the combo boxes all
bound to fields in the form's recordsource? I don't see why it would behave
differently for a combo box than for a text boxes unless (a) the combo box
is unbound, so that it retains its value from record to record, or (b) the
control or its bound field has a default value.

Is your intention with this code just to prevent a record from being saved
unless all required fields are filled in? If so, I would suggest using the
form's BeforeUpdate event to enforce that, rather than the button's Click
event. Then the code in the BeforeUpdate event can cancel the event to keep
the record from being saved.

If you don't check in the form's BeforeUpdate event, there are other ways an
incomplete record could be saved without the user clicking on your command
button.
 

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