How can I make VB lookup a Text field to see if it is empty?

G

Guest

I have written the following, but if the "Edition_Number" field is empty, it
will store an empty record, how can I make it look at that field to see if
there is any text or not?
Private Sub Close_Edition_Number_Form_Click()
On Error GoTo Err_Close_Edition_Number_Form_Click

DoCmd.Save
DoCmd.Close

Exit_Close_Edition_Number_Form_Click:
Exit Sub

Err_Close_Edition_Number_Form_Click:
MsgBox Err.Description
Resume Exit_Close_Edition_Number_Form_Click

End Sub
Thank you in anticipation for your help in this matter.
 
J

Joerg Ackermann

StevenIpek. said:
I have written the following, but if the "Edition_Number" field is
empty, it will store an empty record, how can I make it look at that
field to see if there is any text or not?
Private Sub Close_Edition_Number_Form_Click()
On Error GoTo Err_Close_Edition_Number_Form_Click

DoCmd.Save
DoCmd.Close

Exit_Close_Edition_Number_Form_Click:
Exit Sub

Err_Close_Edition_Number_Form_Click:
MsgBox Err.Description
Resume Exit_Close_Edition_Number_Form_Click

End Sub
Thank you in anticipation for your help in this matter.

Try:

....
If Len("" & Me!Edition_Number) > 0 Then
DoCmd.Save
End If
....

Acki
 
B

Bas Cost Budde

if not isnull(edition_number) then
runcommand accmdsaverecord ' which I prefer over docmd.save
docmd.close acform, me.name
end if
 
P

Pat Hartman

For starters DoCmd.Save saves the form NOT the record. The record is
"quietly" being saved by Access in the background when the form closes. You
need to change this to:
DoCmd.RunCommand acCmdSaveRecord

Any edit code of this nature MUST be placed in the FORM's BeforeUpdate
event. No other event will be satisfactory. If you attempt to put it
anywhere else, you will need to place it in multiple events in order to trap
all the situations in which Access quietly (without notifying you) saves a
record. In the BeforeUpdate event, you can cancel the update if the
required field is empty:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Edition_Number = "" or IsNull(Me.Edition_Number) Then
Cancel = True
MsgBox "blah, blah, blah", vbOKOnly
Me.Edition_Number.SetFocus
End If
End Sub
 

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