leaving field null based on another field (1 Viewer)

jtbrown1955

Registered User.
Local time
Today, 03:16
Joined
May 28, 2005
Messages
17
I have a downtime database that tracks units down, time on, reason down, etc. When a unit goes down, I log the name of the unit and the time down in separate fields. When a unit goes back on line, I log the time on and the reason in separate fields. All this is in a form. When the unit goes on line, I want the user to be forced to enter a reason only after he has entered a time on, not before. The “reason” field must be left blank until the unit is on. How do I do that? I have searched the forum for this and have not found leaving a field blank based on another field’s data. I will supply whatever you need to help me. Thank you.
 

R. Hicks

AWF VIP
Local time
Today, 05:16
Joined
Dec 23, 1999
Messages
619
Hmmm ...

I would simply disable the txtbox for the "reason" until the "time on" has a valid entry ...

RDH
 

jtbrown1955

Registered User.
Local time
Today, 03:16
Joined
May 28, 2005
Messages
17
I didn't mean the reason MUST be left blank as in I don't want anyone entering data. Data cannot be entered until the unit is back on line and then we will have a reason to enter. We will not have a reason until the operator calls and tells us. What I don't want is someone showing the unit on without giving a reason. I can simply "require" data in the reason field, but I cannot move to the next record without an entry. I won't have an entry until someone calls us. I want the reason field to not be left blank AFTER the time on field is filled in.
 

RV

Registered User.
Local time
Today, 11:16
Joined
Feb 8, 2002
Messages
1,115
Use the Before Update event on your form.

Let's say, your control used for entering your time is called txtTimeOn and your control to enter the reason is called txtReasonOn, your code would look like:

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull(Me.txtTimeOn) = False Then
    If IsNull(Me.txtReasonOn) = True Then
    MsgBox "You need to enter a reason"
    Cancel = True
    Else
    End If
Else
End If

End Sub

RV
 

jtbrown1955

Registered User.
Local time
Today, 03:16
Joined
May 28, 2005
Messages
17
It still does not work. I have attached my database. The TimeDown is automatic. You have to fill in the area to get a unit. After the unit is logged, the operator will call and I will double click in the TimeOn and then fill in a reason per the operator. I don't want to go to another record unless the Reason is filled in after the TimeOn is filled in. I am not an expert at all. This database has been a long time building and works well. I am just trying to make the information as accurate as possible. The reports generated must show a reason for the unit being down, and sometimes someone forgets to put a reason in. I stripped the reports and the downtime table information out to lessen the size of the database. Please, any help will be greatly appreciated. I put a refresh button on to show the TimeOn in the sub form above. Thank you.
 

Attachments

  • gasconwork.zip
    234.4 KB · Views: 131

RV

Registered User.
Local time
Today, 11:16
Joined
Feb 8, 2002
Messages
1,115
It still does not work

Yes is does as long as you put a Before Update event on your form.
I've changed to the code a bit so it reflects the names of your controls:

Code:
If IsNull(Me.TimeOn) = False Then
    If IsNull(Me.Combo126) = True Then
    MsgBox "Enter a reason first"
    Cancel = True
    Me.Combo126.SetFocus
    Else
    End If
Else
End If

In order to define events, you need to open your form in design view.
Next, click in the little square top left in your form.
You'll notice that a little solid black square will appear within the square itself.
Next, right click and select Properties from the drop down list.

Navigate to the tab page called "Event".
Click in the property called "Before Update".
A down arrow appears at the right side of the field.
Click on the arrow and select [Event procedure].
You'll notice that a new icon appears at the right side, it comes with three dots.
Click on the icon, this will open the Microsoft VB code form.
Copy and paste the code I supplied you with.
Leave the "default" code lines (Private sub... and End Sub) for what they are.

I am just trying to make the information as accurate as possible

That's a good idea.
Take into account however that this requires a thorough understanding of relational databases, normalization, business rules and processes and last but not least, VBA.

RV
 

jtbrown1955

Registered User.
Local time
Today, 03:16
Joined
May 28, 2005
Messages
17
This works great! I was putting it in the properties of the TimeOn field, not in the form properties. Thank you very much.
 

Users who are viewing this thread

Top Bottom