Search duplicate record on data entry (1 Viewer)

ljoekelsoey4

Registered User.
Local time
Today, 10:23
Joined
Mar 16, 2017
Messages
49
I realise this is an oft covered topic, but I've had trouble implementing the answers of found on other threads.

I'm wanting to check if the entered "CHI", the primary key (text, not number) is already contained in the table immediately after update (or before?) of that field, i.e. just after the CHI has been inputted, and well before the rest of the data is input into the form and the 'save' button reveals the impending error. This is simply to save time for users.

Thanks guys
 

dairees

New member
Local time
Today, 02:23
Joined
Oct 5, 2012
Messages
2
If Dount("CHI", "Table1", "[CHI] = Forms!Form1.txtCHI") > 0 then
Msgbox "Error - that CHI value is already in Table1"
End if

The above is a very simple way to check - you'd need to replace Table1, CHI, Form1 and txtCHI with the relevant values though.
 

Ranman256

Well-known member
Local time
Today, 05:23
Joined
Apr 9, 2015
Messages
4,339
You can have an unbound box,the only box on the form.
Enter CHI,
upon enter, it will either open the detail form full of existing data,
Or
open it empty ,ready for data entry.

Code:
 Sub txtBox_afterupdate()
VKey = Dlookup("[id]","table","[id]='" & txtBox & "'")
If IsNull(vKey) then 
    Docmd.openForm "frmDetail",,,,acFormAdd
    Forms!frmDetail!txtID=me.txtBox
Else
Docmd.openForm "frmDetail",,,"[id]='" & txtBox & "'"  
End if
 

ljoekelsoey4

Registered User.
Local time
Today, 10:23
Joined
Mar 16, 2017
Messages
49
thanks dairees, works perfectly. Thanks also Ranman256 for your response :)
 

Users who are viewing this thread

Top Bottom