I need one line code, only (?)

A

an

I think lack the further down line, where

.... (?)

to work fine.


Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim strMsg As String

If IsNull(Me.FileName) Or _
IsNull(Me.Path) Or _
IsNull(Me.Ponto) Then

strMsg = msgbox("There are field without data. Do
you to continue?", vbYesNo)

If strMsg = vbNo Then
Me.Undo

If strMsg = vbYes Then
' goto next field (Path)
... (?)

End If
End If
End If
End Sub
 
A

Albert D. Kallal

I assume if the user answers no, you thus allow the user to go back and edit
some more?

Your message of:

There are field without data. Do you to continue?"

Does that mean we want to continue to save and exit the record, or continue
and go back and edit the data?

(the above seems a bit confusing to me, and I suspect the end user will be
confused on the above).

Anyway, here is a code snip with some neat coding concepts (such as a "list"
of fields to check). This means you can add 2 or 3 more fields to check..and
not have to midify the rest of the code. And, this code will give you some
ideas as how one could attack this problem. Also, it is not clear what you
want to do if the user decides NOT to edit the blank fields.
(do you save the data and exit...or do you dump changes..and exit?)


Dim strField As String
Dim vFields As Variant
Dim i As Integer

Dim strMsg As Integer

vFields = Split("FileName,Path,Ponto", ",")

For i = 0 To UBound(vFields, 1)
If IsNull(Me(vFields(i))) = True Then
strField = vFields(i)
Exit For
End If
Next i

If strField <> "" Then
strMsg = strField + " does not have data." & vbCrLf & _
"Do you want to go back and edit this Field?"

If MsgBox(strField, vbYesNo + vbExclamation, "Empty Field") = vbYes
Then

Me(strField).SetFocus
Cancel = True

Else

' user does not want to edit empry fields...
' so, dump all edits...and exit is currently
' what this code does...but is that what you want??
Me.Undo
End If
End If
 
A

an

Thanks, ADK, for your reply.

When user click NO, work fine. It turn out without saving.
When user click YES, it turn out and save -1 in the next
field.

I would like, when user lick YES:
To continue for to write data in next field, and so on.

Many thanks.
an
 
A

Albert D. Kallal

an said:
Thanks, ADK, for your reply.

When user click NO, work fine. It turn out without saving.
When user click YES, it turn out and save -1 in the next
field.

Hum, not clear what you mean by -1 in the next field?
I would like, when user lick YES:
To continue for to write data in next field, and so on.

Hum, "write data in next field" is again not clear to me.

The way I have this is that if you click yes, then you go back and edit the
field

If you click no..then all changes to the data was thrown out....

We are talking about a standard form, and the user is just editing the
data..right?
 
A

an

Ok:

1 - With cursor in 1st position, on NameFile field, -1 is
what appear in next Field (Path) when user click Yes and
go out (?).

2 - We are talking about a standard form, and the user is
just editing the data..right?

Exactly. We are talking about a Form to Add new records.
After insert data in 1st field, and if user click YES, the
user be able to edit and write in 2nd field, and so on.
Not go to back, but go to next field.
On last field with data, the operation is completed. Then
is saved new record with all fields with data.

Once more, thanks.
an
 
A

Albert D. Kallal

On last field with data, the operation is completed. Then
is saved new record with all fields with data.

So, our code will NOT run until the user tries to save the record. If the
user tries to save, the record (which can occur due to record movement etc),
then that is when we give the error message that some fields are required,
and PREVENT the user from exiting untill those fields are entered..

So, what we want to do here is tell the user to enter values in those fields
not yet done.

That problem is more simple, and we can use:

Dim strField As String
Dim vFields As Variant
Dim i As Integer

Dim strMsg As Integer

vFields = Split("FileName,Path,Ponto", ",")

For i = 0 To UBound(vFields, 1)
If IsNull(Me(vFields(i))) = True Then
strField = vFields(i)
Exit For
End If
Next i

If strField <> "" Then
strMsg = strField + " does not have data." & vbCrLf & _
"You must enter a value for this Field?"

MsgBox strField, vbYesNo + vbExclamation, "Empty Field"

Me(strField).SetFocus
Cancel = True

End If

Try the above...I think that is what you are looking for...
 
A

an

Morning Albert (Here...)

Sorry for my delay.
When code run, there is an error '13' (Type mistach) on
row

strMsg = strField + " does not have data." & vbCrLf & _
"You must enter a value for this Field?"

Thanks.
an
 
A

an

When we pass mouse over

vbCrLf

appear how variable:

vbCrLf="■■" (two blanks squares)

an
 
A

Albert D. Kallal

Ah....

We have a typeo:

Dim strMsg As Integer

The above should read:

Dim strMsg As string
 
A

an

Hello!
Thanks for your reply.

Sorry but only now arived your response.
I already to make this change.
But now, the problem is more dificult - for me...

I already to emit smoke because, for exemple, when there
is 2nd field without data, appear error in row

Me(strField).SetFocus

I don't know how to go round this.

Many thanks.
an
 

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