duplicate number with messagebox & textbox

  • Thread starter syedalna via AccessMonster.com
  • Start date
S

syedalna via AccessMonster.com

i have a subform, textbox1 is number format and textbox2 is text format..and
both are not a primarykey. subform data is from query (though this will help).


is there away to avoid duplication number in textbox1. when there is a
duplication, it show message box with the detail of textbox2.

Your help is greatly appreciated to solve this matter.


Thank you in advane
 
S

Sean

syedalna via AccessMonster.com said:
i have a subform, textbox1 is number format and textbox2 is text
format..and
both are not a primarykey. subform data is from query (though this will
help).


is there away to avoid duplication number in textbox1. when there is a
duplication, it show message box with the detail of textbox2.

Your help is greatly appreciated to solve this matter.


Thank you in advane


Add an event to the 'on lost focus' of both boxes...

if (cstr(textbox1)) = textbox2) then
msgbox "They're the same!"
end if

Should do the trick, or at least get you in the right direction.

Sean
 
A

Al Campagna

syedalna ,
Use the BeforeUpdate event of TextBox1 to do a Dlookup against all the other
TextBox1 values in your table.
If so... set Cancel = True.
If not...continue normally

Not sure I understand the MsgBox you want to display on dupes... but...

Dim Prompt as String
Dim Title as String
Prompt = Me.TextBox2
Title = "Duplicate Value"
MsgBox Prompt, vbOKOnly, Title
 
S

syedalna via AccessMonster.com

Al Campagna,

Your code is what i'm looking for.

It did identified the duplication & show the message box of the textbox2...
and ADD the record to the table.. I need to have a "Yes" & "No" on the
message box..where
if "Yes" = it will add the record that enter
if "No"= it will Not add the record and the form will return to it natural
state of Add New Data Entry (Add New Record).


Could you show me the code. I do appreciate it very much.

Thanks for your code

Al said:
syedalna ,
Use the BeforeUpdate event of TextBox1 to do a Dlookup against all the other
TextBox1 values in your table.
If so... set Cancel = True.
If not...continue normally

Not sure I understand the MsgBox you want to display on dupes... but...

Dim Prompt as String
Dim Title as String
Prompt = Me.TextBox2
Title = "Duplicate Value"
MsgBox Prompt, vbOKOnly, Title
i have a subform, textbox1 is number format and textbox2 is text format..and
both are not a primarykey. subform data is from query (though this will help).
[quoted text clipped - 5 lines]
Thank you in advane
 
A

Al Campagna

syedalna,
Set up the MsgBox This way...

Dim Prompt as String, Title as String, Response as Integer
Prompt = "Duplicate " & Me.TextBox2 & vbCrLf & " Do you want to add it?"
Title = "Duplicate Value"
Response = MsgBox (Prompt, vbYesNo, Title)
If Response = vbYes Then
'code to add the record
Else
'code to not add the record
End If

--
hth
Al Campagna
Candia Computer Consulting - Candia NH
http://home.comcast.net/~cccsolutions



syedalna via AccessMonster.com said:
Al Campagna,

Your code is what i'm looking for.

It did identified the duplication & show the message box of the textbox2...
and ADD the record to the table.. I need to have a "Yes" & "No" on the
message box..where
if "Yes" = it will add the record that enter
if "No"= it will Not add the record and the form will return to it natural
state of Add New Data Entry (Add New Record).


Could you show me the code. I do appreciate it very much.

Thanks for your code

Al said:
syedalna ,
Use the BeforeUpdate event of TextBox1 to do a Dlookup against all the other
TextBox1 values in your table.
If so... set Cancel = True.
If not...continue normally

Not sure I understand the MsgBox you want to display on dupes... but...

Dim Prompt as String
Dim Title as String
Prompt = Me.TextBox2
Title = "Duplicate Value"
MsgBox Prompt, vbOKOnly, Title
i have a subform, textbox1 is number format and textbox2 is text format..and
both are not a primarykey. subform data is from query (though this will help).
[quoted text clipped - 5 lines]
Thank you in advane
 
S

syedalna via AccessMonster.com

al campagna,
This code prompt me (Yes/ No) even if the data has NO DUPLICATES..

how could i do it, like this:-

if data duplicates= it will Not add the record and the form will return to it
natural state, add new record
if date has NO DUPLICATES= it will add data automatically, withour promp me
any thing ( like noting happen)

your suggestion is much appciated

Al Campagna,

Your code is what i'm looking for.

It did identified the duplication & show the message box of the textbox2...
and ADD the record to the table.. I need to have a "Yes" & "No" on the
message box..where
if "Yes" = it will add the record that enter
if "No"= it will Not add the record and the form will return to it natural
state of Add New Data Entry (Add New Record).

Could you show me the code. I do appreciate it very much.

Thanks for your code
syedalna ,
Use the BeforeUpdate event of TextBox1 to do a Dlookup against all the other
[quoted text clipped - 15 lines]
 
A

Al Campagna

syedalna,
I've been on vacation for a week, so sorry for the dealy in responding.
I thought you just needed the message box part....
All you would need to do is a Dlookup just before the MsgBox to determine if a
duplicate exits, then the Yes/No to add or not.

Dim Prompt as String, Title as String, Response as Integer
Refresh
If IsNull ("[YourFieldName]", "yourTable", "YourField = " & Textbox1) Then
Prompt = "Duplicate " & Me.TextBox2 & vbCrLf & " Do you want to add it?"
Title = "Duplicate Value"
Response = MsgBox (Prompt, vbYesNo, Title)
If Response = vbYes Then
'code to add the record
Else
'code to not add the record
End If
Else
Exit Sub
End Sub

I banged this out, so please check for any typos.

--
hth
Al Campagna
Candia Computer Consulting - Candia NH
http://home.comcast.net/~cccsolutions


syedalna via AccessMonster.com said:
al campagna,
This code prompt me (Yes/ No) even if the data has NO DUPLICATES..

how could i do it, like this:-

if data duplicates= it will Not add the record and the form will return to it
natural state, add new record
if date has NO DUPLICATES= it will add data automatically, withour promp me
any thing ( like noting happen)

your suggestion is much appciated

Al Campagna,

Your code is what i'm looking for.

It did identified the duplication & show the message box of the textbox2...
and ADD the record to the table.. I need to have a "Yes" & "No" on the
message box..where
if "Yes" = it will add the record that enter
if "No"= it will Not add the record and the form will return to it natural
state of Add New Data Entry (Add New Record).

Could you show me the code. I do appreciate it very much.

Thanks for your code
syedalna ,
Use the BeforeUpdate event of TextBox1 to do a Dlookup against all the other
[quoted text clipped - 15 lines]
Thank you in advane
 

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