Msgbox prompt for existing record

M

mel

Hi there I would be extremely grateful if someone could point me in the right
direction - I am trying to display a message for when existing data is
entered: I keep getting error messages such as "you canceled the previous
operation"

Private Sub bkng_number_BeforeUpdate(Cancel As Integer)
Dim ians As Integer
If (IsNull(DLookup("[bkngnmbr]", "bookings", "[bkngnmbr] = " &
Me.bkng_number))) Then
ians = MsgBox("Booking number Already Exists! OK to Amend?," & vbCrLf & "OK
to Amend?," & "Cancel to enter New Booking Number", vbOKCancel)
Cancel = False
If ians = vbCancel Then
Me.Undo
Else
Me!bkngnmbr.Undo
'me!bkngnmbr.setfocus
Exit Sub
End If
End If
 
G

Gijs Beukenoot

From mel :
Hi there I would be extremely grateful if someone could point me in the right
direction - I am trying to display a message for when existing data is
entered: I keep getting error messages such as "you canceled the previous
operation"

Private Sub bkng_number_BeforeUpdate(Cancel As Integer)
Dim ians As Integer
If (IsNull(DLookup("[bkngnmbr]", "bookings", "[bkngnmbr] = " &
Me.bkng_number))) Then
ians = MsgBox("Booking number Already Exists! OK to Amend?," & vbCrLf & "OK
to Amend?," & "Cancel to enter New Booking Number", vbOKCancel)
Cancel = False
If ians = vbCancel Then
Me.Undo
Else
Me!bkngnmbr.Undo
'me!bkngnmbr.setfocus
Exit Sub
End If
End If

You can't .undo in the beforeupdate. Use the built-in Cancel from the
function :

if Nz(DLookup("[bkngnmbr]", "bookings", "[bkngnmbr] = " &
Me.bkng_number),"") <> "" Then
If MsgBox("Booking number Already Exists! OK to Amend?," & vbCrLf &
"OK to Amend?," & "Cancel to enter New Booking Number",
vbQuestion+vbOKCancel)
'Try again
Cancel = true
Me.bkngnmbr.setfocus
else
'Erm, this is from top of my head, might need to check the
parameters of findfirst
Dim rs as DAO.RecordSet
Set rs = me.recordsetclone
rs.findfirst "[bkngnmbr] = " & Me.bkng_number
me.bookmark = rs.bookmark
rs.close
set rs = nothing
endif
endif
 
G

Gijs Beukenoot

From Gijs Beukenoot :
From mel :
Hi there I would be extremely grateful if someone could point me in the
right direction - I am trying to display a message for when existing data
is entered: I keep getting error messages such as "you canceled the
previous operation"

Private Sub bkng_number_BeforeUpdate(Cancel As Integer)
Dim ians As Integer
If (IsNull(DLookup("[bkngnmbr]", "bookings", "[bkngnmbr] = " &
Me.bkng_number))) Then
ians = MsgBox("Booking number Already Exists! OK to Amend?," & vbCrLf & "OK
to Amend?," & "Cancel to enter New Booking Number", vbOKCancel)
Cancel = False
If ians = vbCancel Then
Me.Undo
Else
Me!bkngnmbr.Undo
'me!bkngnmbr.setfocus
Exit Sub
End If
End If

You can't .undo in the beforeupdate. Use the built-in Cancel from the
function :

if Nz(DLookup("[bkngnmbr]", "bookings", "[bkngnmbr] = " & Me.bkng_number),"")
<> "" Then
If MsgBox("Booking number Already Exists! OK to Amend?," & vbCrLf & "OK to
Amend?," & "Cancel to enter New Booking Number", vbQuestion+vbOKCancel)
'Try again
Cancel = true
Me.bkngnmbr.setfocus
else
'Erm, this is from top of my head, might need to check the parameters
of findfirst
Dim rs as DAO.RecordSet
Set rs = me.recordsetclone
rs.findfirst "[bkngnmbr] = " & Me.bkng_number
me.bookmark = rs.bookmark
rs.close
set rs = nothing
endif
endif

Hmm, I mixed up two comments. The else part is searching the recordset
and showing the entered record in the form. Not sure if you needed
that...
 
G

Graham R Seach

But you can Undo the control's change:
Me!bkng_number.Undo
Cancel = True

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

Gijs Beukenoot said:
From mel :
Hi there I would be extremely grateful if someone could point me in the
right direction - I am trying to display a message for when existing data
is entered: I keep getting error messages such as "you canceled the
previous operation"

Private Sub bkng_number_BeforeUpdate(Cancel As Integer)
Dim ians As Integer
If (IsNull(DLookup("[bkngnmbr]", "bookings", "[bkngnmbr] = " &
Me.bkng_number))) Then
ians = MsgBox("Booking number Already Exists! OK to Amend?," & vbCrLf &
"OK to Amend?," & "Cancel to enter New Booking Number", vbOKCancel)
Cancel = False
If ians = vbCancel Then
Me.Undo
Else
Me!bkngnmbr.Undo
'me!bkngnmbr.setfocus
Exit Sub
End If
End If

You can't .undo in the beforeupdate. Use the built-in Cancel from the
function :

if Nz(DLookup("[bkngnmbr]", "bookings", "[bkngnmbr] = " &
Me.bkng_number),"") <> "" Then
If MsgBox("Booking number Already Exists! OK to Amend?," & vbCrLf & "OK
to Amend?," & "Cancel to enter New Booking Number", vbQuestion+vbOKCancel)
'Try again
Cancel = true
Me.bkngnmbr.setfocus
else
'Erm, this is from top of my head, might need to check the parameters
of findfirst
Dim rs as DAO.RecordSet
Set rs = me.recordsetclone
rs.findfirst "[bkngnmbr] = " & Me.bkng_number
me.bookmark = rs.bookmark
rs.close
set rs = nothing
endif
endif
 

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