flaviooooo
Programmer
Hi,
I have a question that I think will be simple to answer, but I can't figure it out.
I have a table that has a key consisting of Purchase_Order and Item.
I also have a form where the users can create new records into that table.
On the form is a button that triggers the following code:
DoCmd.GoToRecord , , A_NEWREC
But I have a problem when people try to enter a record that already exists. Where do I check for this, and how can I avoid the error messages?
I tried something like this on the after update of the Item field:
strsql = "select * from AFROEPEN_AANKOOP_HEADER where [Purchorder] = '" & Me.PURCHORDER & "' and [ITEM] = '" & Me.ITEM & "'"
Set rs = CurrentDb.OpenRecordset(strsql)
If rs.EOF = False Then
MsgBox ("This order is allready in the table")
' DoCmd.DoMenuItem A_FORMBAR, A_EDITMENU, A_SELECTRECORD_V2, , A_MENU_VER20
' DoCmd.DoMenuItem A_FORMBAR, A_EDITMENU, A_DELETE_V2, , A_MENU_VER20
Me.RecordsetClone.FindFirst "[Purchorder] = '" & Me.PURCHORDER & "' and [ITEM] = '" & Me.ITEM & "'"
Me.Bookmark = Me.RecordsetClone.Bookmark
end if
But this gives me an error that I can't go to the specified record.
Thanks in advance
I have a question that I think will be simple to answer, but I can't figure it out.
I have a table that has a key consisting of Purchase_Order and Item.
I also have a form where the users can create new records into that table.
On the form is a button that triggers the following code:
DoCmd.GoToRecord , , A_NEWREC
But I have a problem when people try to enter a record that already exists. Where do I check for this, and how can I avoid the error messages?
I tried something like this on the after update of the Item field:
strsql = "select * from AFROEPEN_AANKOOP_HEADER where [Purchorder] = '" & Me.PURCHORDER & "' and [ITEM] = '" & Me.ITEM & "'"
Set rs = CurrentDb.OpenRecordset(strsql)
If rs.EOF = False Then
MsgBox ("This order is allready in the table")
' DoCmd.DoMenuItem A_FORMBAR, A_EDITMENU, A_SELECTRECORD_V2, , A_MENU_VER20
' DoCmd.DoMenuItem A_FORMBAR, A_EDITMENU, A_DELETE_V2, , A_MENU_VER20
Me.RecordsetClone.FindFirst "[Purchorder] = '" & Me.PURCHORDER & "' and [ITEM] = '" & Me.ITEM & "'"
Me.Bookmark = Me.RecordsetClone.Bookmark
end if
But this gives me an error that I can't go to the specified record.
Thanks in advance