Need help about required fields

A

access2002-73

Hello,
I have an account cancellations db (access 2002) for the company. I need to
have certain fields of the dB required (not left blank). However, these
fields should only be required to be filled in when a status field is changed
to "closed" from the drop down box. Status field has other selections such as
new, not valid etc...
Is there anyway I can use a micro or formula to create a link between status
field "closed" and other fields which become required (not left blank) when
status changed to "closed"? I appreciate all your help. Thank you.
 
J

JP

You have to do it with some event code. There are a couple of different
approaches, I'll suggest two of them:

In the before update event of the form, check to see if the status is now
"closed". If it is, then check those fields that you want as required to
make sure that something has been entered. If not, give the user an error
message and cancel the update.

Another alternative is in the after update event of the status field. Check
to see if the status is now "closed". If it is, then set the required
property of the appropriate fields to true. Just don't forget to unset them
(or not) in the Current event.
 
G

Guest

hi,
at the start of your code you can check these fields for
the conditions you just described. something simple like

if me.status = "closed" and me.acertainfield = "" and _
me.anotherfield = "" then
msgbox ("need input into cretain other fields")
exit sub
else
continue on with regular code.
end if
if the conditions are not met, the user is dumped out of
the code until the user meets all of the conditions.
 
K

KT

My If...Then...Else doesn't evaluate properly using the
given example.

I need both the txtQty and the txtMemo to be populated so
I've got:
If (Me.txtQty = "") Or (Me.txtMemo = "") Then
MsgBox "Quantity and memo must be filled in.", _
vbOKOnly + vbExclamation, "Incomplete entry"
Exit Sub
Else: Debug.Print "all entries complete"
End If
When neither txtQty txtMemo is populated, ie. they're both
Null the subroutine still continues.

I have also tried (Me.txtQty Is Null) Or (Me.txtMemo Is
Null) but then get a run-time error: Object required.
 
B

Brendan Reynolds

To check for Null in VBA code, use the IsNull function ...

If IsNull(Me.txtQty) Or IsNull(Me.txtMemo) Then

Alternatively, the following will catch either Null or empty strings ...

If Len(Me.txtQty & vbNullString) = 0 Or Len(Me.txtMemo & vbNullString) = 0
Then
 

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