Help with Data Present for a access program

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

Guest

Hi, I am working on a program and I wanted to have the record set up to where
each field has to be entered in order to exit the record. Some one told me
about using Data Present, but i have never heard of data present. Could
someone help me out.

Thank you
Sheria
 
I've never heard of it either!

What you can do is put logic in the form's BeforeInsert event to check each
field. Something like:

Private Sub Form_BeforeInsert(Cancel As Integer)

Dim strMessage As String

If Len(Me.Field1 & "") = 0 Then
Cancel = True
strMessage = strMessage & "Field1 has no data." & vbCrLf
End If

If Len(Me.Field2 & "") = 0 Then
Cancel = True
strMessage = strMessage & "Field2 has no data." & vbCrLf
End If

If Len(strMessage) > 0 Then
MsgBox strMessage
End If

End Sub

The inclusion of Cancel = True means that the insertion will not take place
if one or more empty fields is found.
 
I think you meant "Data Validation" which includes checking for data entry
also.
 
Thank you, one question will this work for check boxes as well I have a total
of 4 and at least one will need to be checked before exiting the record.
 
Thank you, for your help. I will start using the required field.

Thanks
 
Oh ok, I am not really sure, someone just told me that I need to write a code
for Data Present.
 
You'd have to modify the code slightly.

If (Me.Check1 And Me.Check2 And Me.Check3 And Me.Check4) = False Then
Cancel = True
strMessage = strMessage & "You haven't selected any checkboxes." &
vbCrLf
End If

Another way of expressing that is

If (Me.Check1 + Me.Check2 + Me.Check3 + Me.Check4) = 0 Then
Cancel = True
strMessage = strMessage & "You haven't selected any checkboxes." &
vbCrLf
End If
 
Hi, I tried the code and nothing happend, I tried both of them an error
message keeps coming up with the 2nd & sign, so I did not use the 2nd & sign.
No errors have appeared so far, but the code is just not working. I will
continue trying to see if it will work. Thank you for your help
 
Hard to tell, but it looks as though there was word-wrap in what I posted.

The vbCrLf should be on the same line as the strMessage = strMessage & ....
stuff

What do you mean by "the code is just not working"?

Post exactly what code you're using. What is happening, and what should be
happening?
 
Private Sub Form_BeforeInsert(Cancel As Integer)
Dim strMessage As String

If (Me.Incoming_Call + Me.Outgoing_Call + Me.Incoming_Email +
Me.Return_Call) = 0 Then
Cancel = True
strMessage = strMessage & "You have to select a check box." & vbCrLF
End If

End Sub

When a Rep tries to go to another record without checking a box, the message
should appear and not continue to the next record (What should happen). But
with the code if the check boxes are not check, you are still able to go to
another record (that's what happening at this point).

Thanks Again
 
That was intended to be part of a larger series of checking.

First of all, you need to put code

If Len(strMessage) > 0 Then
MsgBox strMessage
End If

before the End Sub.

Does it actually insert the row though?
 
Thank you I will try that with the code, yes the rows are inserted, but there
should be a msg box before the insert.

Thank you again
 
Sheria said:
Thank you I will try that with the code, yes the rows are inserted,
but there should be a msg box before the insert.

PMFJI
From: Help | Contents | Programming Information | When Events Occur | Find
out when events occur

--------------------------------------------------------

Order of events for records on forms

<snip>

Creating a new record
When you move the focus to a new (blank) record on a form and then create a
new record by typing in a control, the following sequence of events occurs:

Current (form) Þ Enter (control) Þ GotFocus (control) Þ BeforeInsert (form)
Þ AfterInsert (form)

The BeforeUpdate and AfterUpdate events for the controls on the form and for
the new record occur after the BeforeInsert event and before the AfterInsert
event.
 
Ok Thank You,

I will give it a try and see what happens. Thanks for your help.
 

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

Back
Top