473,509 Members | 2,946 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I prevent to add double data

Hi all.

I have a small problem:

I have a table with standard data (about 25 records).
When a button is pressed on a form a query is being run that adds the
records from this table to an other table as well as a date that is put
in a box on the same form.

This all works fine. If however this date (with its 25 records) is
already in the new table then it shouldn't be added.

I can't use the properties of the table itself because later on I want
to be able to add records that already exist.

I hope I am making sense so far still ;)

I think I should somehow check if the date that is filled in this box
is already present in the table. If not, then add the date, if so then
not.

Can anyone help me with this one?

With best regards,
Frans-Jan

Nov 13 '05 #1
4 1418
Hi there,
Hope you can adapt this logic. This is a sub called from a command button
to do a compare
of the records loaded in the form against a date in a textbox on the form.
txtDate is the unbound
textbox on the form, SaveDt is the field in the table.

HTH -Linda

Private Sub cmdCheckDate_Click()
Dim rst As Recordset

Set rst = Me.RecordsetClone

rst.FindFirst "SaveDt = #" & Me!txtDate & "#"

If rst.NoMatch Then
MsgBox "OK to add data"
Else
MsgBox "This date is in the table."
End If
End Sub

<fr******@vanrooijen.nl> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Hi all.

I have a small problem:

I have a table with standard data (about 25 records).
When a button is pressed on a form a query is being run that adds the
records from this table to an other table as well as a date that is put
in a box on the same form.

This all works fine. If however this date (with its 25 records) is
already in the new table then it shouldn't be added.

I can't use the properties of the table itself because later on I want
to be able to add records that already exist.

I hope I am making sense so far still ;)

I think I should somehow check if the date that is filled in this box
is already present in the table. If not, then add the date, if so then
not.

Can anyone help me with this one?

With best regards,
Frans-Jan

Nov 13 '05 #2
FJ
Hi Linda,

Thanks for your help so far. I get the idea and agree with you that
this should work perfectly.

However... the table isn't loaded in any form. Any idea on what the
code should then look like?
Thanks already for the great help :)
Best regards,
Frans-Jan

Nov 13 '05 #3
don't enter data directly into the table. Do it through a form. Then
you can use the BeforeInsert event to do whatever complex checking you
want. Or just enforce uniqueness on multiple fields.

Nov 13 '05 #4
FJ wrote:
However... the table isn't loaded in any form. Any idea on what the
code should then look like?


If you absolutely insist on loading data directly into the table itself
(not adviseable, especially if others are going to add data and not just
you) alter the table properties (don't panic here - I remember you
saying that you wanted to add data from other tables later - read on).

Go to the date field in your table and changed the Indexed property for
the date to

Yes (No Duplicates)

Save the table and enter your data. Once you are happy with the data
you've added and are ready to bring in more data as you mentioned,
change the indexed property back to No.

As Pietlinden states though, you should designa form for entering data.
You can use Linda's code in the record before update event.

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What's UP, Dittoooooo?" - Ditto
Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4151
by: Otto Wyss | last post by:
I have the following statements int page.x = page.x * ppiScr.x / 25.4; int page.y = page.y * ppiScr.y / 25.4; While VC++ is happy GCC complains the above warning. How can I get rid of these...
6
51898
by: John Bowman | last post by:
Hi All, I must be missing something really obvious, so I'd appreciate someone helping me out. I have a simple Windows form that currently only has a title bar (aka the Text Property is set) and...
6
5619
by: YUS | last post by:
Hi, I've got a problem. I have a program that ask for a number to the user. If the user put a letter instead of a number the program crashes (loop). How can I prevent this ? I've tried with...
5
1496
by: rn5a | last post by:
A Web Form has a TextBox within a DataGrid wherein users are expected to enter only whole numbers. It should be validated so that the TextBox doesn't remain blank or any non-numeric data is...
0
6159
by: josephkorn | last post by:
Hi all. I have a problem in my website in trying to prevent a user from double submitting the form. I am calling a subroutine from my page_load event that passes in the commandbutton that I want...
5
9972
by: Vincent | last post by:
I have a bound listbox control on one of my forms that has an associated afterupdate event. When this event is invoked, I lock the control to prevent the user from clicking on it more than once....
6
19715
by: Fnord Nase | last post by:
Hi. We're using the dblclick event in some parts of a web app interface, which works okay, but when a user double clicks on a text element, the browser selects some text before executing the...
4
5809
by: jeff_j_dunlap | last post by:
I am trying to display some numbers but they are displaying in e- notation as seen in the output below. double a = 500000; double b = 1400000; cout << "a = " << a << endl; // prints "a =...
4
2137
by: PJ6 | last post by:
Is there a way to prevent the double-click event on an element from causing IE6 to select everything? Cancelling the event doesn't work. Paul
3
4631
by: Wayne | last post by:
I'm building a bookings database for trucks that among other things captures the TruckName, LoadDate, LoadTime, UnloadDate and UnloadTime. Is there a simple way to prevent double bookings for any...
0
7234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7136
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7344
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
441
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.