Required information in text box VBA

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

Guest

Hello, I have a form that supervisors put information into threw out the
shift on about 7 new records a shift. The reason being they keep track of
diferent things happining to a machine we are running ect. and need to filter
threw the records threw out the shift. My question is that there are some
combo boxes that has to have information in them when the entire database is
closed. I cant set the tables "Required to yes because they wont be able to
scroll threw the record to keep entering new information. Is there code I can
add that these combo and text boxes require information in them when the
database is closed?

Thanks,
Chad
 
Hi Chad

Go to the Form's property sheet and choose the Event tab.
Next to "On Unload" choose [Event Procedure] and click the 3 dots to the
right of the box.

You will see...

Private Sub Form_Unload(Cancel As Integer)

End Sub

....between these lines you can check the fields you need to.
Let's say you have a text field called SupervisorName which isn't allowed to
be blank or null, then use...

If Nz(Me.SupervisorName) = "" Then
MsgBox "Please enter the Supervisor Name"
Cancel = True 'This cancels the close
End If

You can check other fields in the same way.

Regards

Andy Hull
 
Can you give me an example of 3 fields? Thanks!!!

Andy Hull said:
Hi Chad

Go to the Form's property sheet and choose the Event tab.
Next to "On Unload" choose [Event Procedure] and click the 3 dots to the
right of the box.

You will see...

Private Sub Form_Unload(Cancel As Integer)

End Sub

...between these lines you can check the fields you need to.
Let's say you have a text field called SupervisorName which isn't allowed to
be blank or null, then use...

If Nz(Me.SupervisorName) = "" Then
MsgBox "Please enter the Supervisor Name"
Cancel = True 'This cancels the close
End If

You can check other fields in the same way.

Regards

Andy Hull


Chad said:
Hello, I have a form that supervisors put information into threw out the
shift on about 7 new records a shift. The reason being they keep track of
diferent things happining to a machine we are running ect. and need to filter
threw the records threw out the shift. My question is that there are some
combo boxes that has to have information in them when the entire database is
closed. I cant set the tables "Required to yes because they wont be able to
scroll threw the record to keep entering new information. Is there code I can
add that these combo and text boxes require information in them when the
database is closed?

Thanks,
Chad
 
Hi Chad

You could use something like below. Have a good look at the code and the MS
Access help to get more understanding of how it works. Then you will be able
to make your own amendments to make it work exactly as you want and will be
able to apply similar code to different situations in the future as you'll
rarely find one piece of code that you can paste into any situation.

Private Sub Form_Unload(Cancel As Integer)

Dim MsgString as String

MsgString = "The following information must be entered..."

If Nz(Me.SupervisorName) = "" Then
MsgString = MsgString & vbcr & "Supervisor Name"
Cancel = True
End If

If Nz(Me.OtherTextField) = "" Then
MsgString = MsgString & vbcr & "Other Text Field"
Cancel = True
End If

If Nz(Me.ComboBoxName) = "" Then
MsgString = MsgString & vbcr & "ComboBox Name"
Cancel = True
End If

If Cancel = True Then
MsgBox MsgString
End If

End Sub


Hope this helps. Post back if you need more info.

Andy Hull


Chad said:
Can you give me an example of 3 fields? Thanks!!!

Andy Hull said:
Hi Chad

Go to the Form's property sheet and choose the Event tab.
Next to "On Unload" choose [Event Procedure] and click the 3 dots to the
right of the box.

You will see...

Private Sub Form_Unload(Cancel As Integer)

End Sub

...between these lines you can check the fields you need to.
Let's say you have a text field called SupervisorName which isn't allowed to
be blank or null, then use...

If Nz(Me.SupervisorName) = "" Then
MsgBox "Please enter the Supervisor Name"
Cancel = True 'This cancels the close
End If

You can check other fields in the same way.

Regards

Andy Hull


Chad said:
Hello, I have a form that supervisors put information into threw out the
shift on about 7 new records a shift. The reason being they keep track of
diferent things happining to a machine we are running ect. and need to filter
threw the records threw out the shift. My question is that there are some
combo boxes that has to have information in them when the entire database is
closed. I cant set the tables "Required to yes because they wont be able to
scroll threw the record to keep entering new information. Is there code I can
add that these combo and text boxes require information in them when the
database is closed?

Thanks,
Chad
 
Thanks Andy it worked like a charm!!!!

Andy Hull said:
Hi Chad

You could use something like below. Have a good look at the code and the MS
Access help to get more understanding of how it works. Then you will be able
to make your own amendments to make it work exactly as you want and will be
able to apply similar code to different situations in the future as you'll
rarely find one piece of code that you can paste into any situation.

Private Sub Form_Unload(Cancel As Integer)

Dim MsgString as String

MsgString = "The following information must be entered..."

If Nz(Me.SupervisorName) = "" Then
MsgString = MsgString & vbcr & "Supervisor Name"
Cancel = True
End If

If Nz(Me.OtherTextField) = "" Then
MsgString = MsgString & vbcr & "Other Text Field"
Cancel = True
End If

If Nz(Me.ComboBoxName) = "" Then
MsgString = MsgString & vbcr & "ComboBox Name"
Cancel = True
End If

If Cancel = True Then
MsgBox MsgString
End If

End Sub


Hope this helps. Post back if you need more info.

Andy Hull


Chad said:
Can you give me an example of 3 fields? Thanks!!!

Andy Hull said:
Hi Chad

Go to the Form's property sheet and choose the Event tab.
Next to "On Unload" choose [Event Procedure] and click the 3 dots to the
right of the box.

You will see...

Private Sub Form_Unload(Cancel As Integer)

End Sub

...between these lines you can check the fields you need to.
Let's say you have a text field called SupervisorName which isn't allowed to
be blank or null, then use...

If Nz(Me.SupervisorName) = "" Then
MsgBox "Please enter the Supervisor Name"
Cancel = True 'This cancels the close
End If

You can check other fields in the same way.

Regards

Andy Hull


:

Hello, I have a form that supervisors put information into threw out the
shift on about 7 new records a shift. The reason being they keep track of
diferent things happining to a machine we are running ect. and need to filter
threw the records threw out the shift. My question is that there are some
combo boxes that has to have information in them when the entire database is
closed. I cant set the tables "Required to yes because they wont be able to
scroll threw the record to keep entering new information. Is there code I can
add that these combo and text boxes require information in them when the
database is closed?

Thanks,
Chad
 
Back
Top