What am i missing?

Sam Summers

Registered User.
Local time
Today, 17:15
Joined
Sep 17, 2001
Messages
939
Hi there,

I must be missing a small point here.
I am simply trying to ensure that users can not enter no data and that after entering an item that i check to see if they require an EN Number before the item is saved.
At the moment it is not quite working. I seem to be able to make it save the item but not without checking if they require an EN Number first.

Here is the code:

Dim Msg, Style, Title, Response

Me.EquipDescription.SetFocus
If Me.EquipDescription.Text = "" Or IsNull(EquipDescription) Then
DoCmd.Beep
MsgBox "Please enter an Item", vbOKOnly + vbExclamation, "No Data entered"
End
End If
Me.ENNumber.SetFocus
If Me.ENNumber.Text = "" Or IsNull(ENNumber) Then
Msg = "Does this item have an EN Number?"
Style = vbYesNo + vbQuestion
Title = "EquiTrac"
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
Me.ENNumber.SetFocus
'End
Else
End If
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close acForm, "AddAccessfrm", acSaveYes
DoCmd.OpenForm "AddAccessfrm", acNormal
End If

Thanks in advance
 
Try this:

Code:
Dim Msg, Style, Title

    If Me.EquipDescription.Text = "" Or IsNull(Me.EquipDescription) Then
        DoCmd.Beep
        MsgBox "Please enter an Item", vbOKOnly + vbExclamation, "No Data entered"
        Me.EquipDescription.SetFocus
        End
    End If
    
    If Me.ENNumber.Text = "" Or IsNull(Me.ENNumber) Then
        Msg = "Does this item have an EN Number?"
        Style = vbYesNo + vbQuestion
        Title = "EquiTrac"
        
            If MsgBox(Msg, Style, Title) = vbYes Then
                Me.ENNumber.SetFocus
                End
            Else
                DoCmd.RunCommand acCmdSaveRecord
                DoCmd.Close acForm, "AddAccessfrm", acSaveYes
                DoCmd.OpenForm "AddAccessfrm", acNormal
            End If
            
    End If
________
Mazda rx-5 specifications
 
Last edited:
Thanks for the help.
That put me on the right track but still didn't work.
This is what finally worked:-

Dim Msg, Style, Title

Me.EquipDescription.SetFocus

If Me.EquipDescription.Text = "" Or IsNull(Me.EquipDescription) Then
DoCmd.Beep
MsgBox "Please enter an Item", vbOKOnly + vbExclamation, "No Data entered"
Me.EquipDescription.SetFocus
End
End If

Me.ENNumber.SetFocus

If Me.ENNumber.Text = "" Or IsNull(Me.ENNumber) Then
Msg = "Does this item have an EN Number?"
Style = vbYesNo + vbQuestion
Title = "EquiTrac"

If MsgBox(Msg, Style, Title) = vbYes Then
Me.ENNumber.SetFocus
End
Else
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close acForm, "AddAccessfrm", acSaveYes
DoCmd.OpenForm "AddAccessfrm", acNormal
End
End If
End If

DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close acForm, "AddAccessfrm", acSaveYes
DoCmd.OpenForm "AddAccessfrm", acNormal
 
There are several probs here, you should use the BeforeUpdate event to trap the missing entries with Cancel=True

DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close acForm, "AddAccessfrm", acSaveYes
DoCmd.OpenForm "AddAccessfrm", acNormal

DoCmd.Close acForm, "AddAccessfrm", acSaveYes
is not saving the record, it saves changes made to the design of the form and is therefore redundant, as is closing and re-opening the form

DoCmd.RunCommand acCmdSaveRecord
Me.Requery
will suffice assuming AddAccessfrm is the form that relates to the code
 

Users who are viewing this thread

Back
Top Bottom