PC Review


Reply
Thread Tools Rate Thread

Avoid duplicate entries

 
 
Chris Nebinger
Guest
Posts: n/a
 
      2nd Jun 2004
Dim strSQL as String
StrSQL = "Select * from [Drawing History Tbl] Where "
strSQL = StrSQL & " [Drawing Number] = '" & Forms![Drawing
Management Frm]![Drawing Number].Value & "' "
strSQL = strSQL & " AND [Drawing Issue] = '" &
Me.Combo2.Value & "'"


'Note, if [Drawing Number] is a number, remove the '
'Same for [Drawing Issue]

Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset(strSQL)
'If .EOF, then that record doesn't exist
if rst.EOF then
rst.AddNew
rst("Drawing Number") = Forms![Drawing Management Frm]!
[Drawing Number].Value
rst("Drawing Issue") = Me.Combo2.Value
rst("Associated Project") = Me.Combo4.Value
rst.Update
rst.Close

>-----Original Message-----
>Hello
>
>I've created a "pop-up" form that load where a user

specifies a drawing number and issue and then presses the
run button which runs the following code:
>
> Dim rst As DAO.Recordset
> Set rst = CurrentDb.OpenRecordset("Drawing

History Tbl")
> rst.AddNew
> rst("Drawing Number") = Forms![Drawing

Management Frm]![Drawing Number].Value
> rst("Drawing Issue") = Me.Combo2.Value
> rst("Associated Project") =

Me.Combo4.Value
> rst.Update
> rst.Close
>
>I would like to include this code in an if statement

that would first verify that there isn't already a
recordset with those values to avoid duplicate entries.
Could someone guide me a bit.
>
>Thanks
>
>Daniel
>.
>

 
Reply With Quote
 
 
 
 
Chris Nebinger
Guest
Posts: n/a
 
      2nd Jun 2004
BAH, hit return to soon:

Code should be:

Dim strSQL as String
StrSQL = "Select * from [Drawing History Tbl] Where "
strSQL = StrSQL & " [Drawing Number] = '" & Forms![Drawing
Management Frm]![Drawing Number].Value & "' "
strSQL = strSQL & " AND [Drawing Issue] = '" &
Me.Combo2.Value & "'"


'Note, if [Drawing Number] is a number, remove the '
'Same for [Drawing Issue]

Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset(strSQL)
'If .EOF, then that record doesn't exist
if rst.EOF then
rst.AddNew
rst("Drawing Number") = Forms![Drawing Management Frm]!
[Drawing Number].Value
rst("Drawing Issue") = Me.Combo2.Value
rst("Associated Project") = Me.Combo4.Value
rst.Update
Else
'REcord Exists
MsgBox "This action has been stopped bacause
it would create a duplicate entry of drawing " & Forms!
[Drawing Management Frm]![Drawing Number].Value & " " &
Me.Combo2.Value & "." & vbCrLf & _
"Please validate the drawing issue that you
are trying to create, verify the existing entries in the
database and try again if neccessary.",
vbExclamation, "Duplicate entry warning"
End If

rst.Close


The method you proposed would be very slow on a large
table, especially since it is looping through every record
and checking the value. For future reference, consider
using .Seek or .FindFirst methods, as well as only opening
Forward-Only recordsets.

Chris Nebinger

>-----Original Message-----
>Dim strSQL as String
>StrSQL = "Select * from [Drawing History Tbl] Where "
>strSQL = StrSQL & " [Drawing Number] = '" & Forms!

[Drawing
>Management Frm]![Drawing Number].Value & "' "
>strSQL = strSQL & " AND [Drawing Issue] = '" &
>Me.Combo2.Value & "'"
>
>
>'Note, if [Drawing Number] is a number, remove the '
>'Same for [Drawing Issue]
>
>Dim rst As DAO.Recordset
>Set rst = CurrentDb.OpenRecordset(strSQL)
>'If .EOF, then that record doesn't exist
>if rst.EOF then
>rst.AddNew
>rst("Drawing Number") = Forms![Drawing Management Frm]!
>[Drawing Number].Value
>rst("Drawing Issue") = Me.Combo2.Value
>rst("Associated Project") = Me.Combo4.Value
>rst.Update
>rst.Close
>
>>-----Original Message-----
>>Hello
>>
>>I've created a "pop-up" form that load where a user

>specifies a drawing number and issue and then presses the
>run button which runs the following code:
>>
>> Dim rst As DAO.Recordset
>> Set rst = CurrentDb.OpenRecordset("Drawing

>History Tbl")
>> rst.AddNew
>> rst("Drawing Number") = Forms![Drawing

>Management Frm]![Drawing Number].Value
>> rst("Drawing Issue") = Me.Combo2.Value
>> rst("Associated Project") =

>Me.Combo4.Value
>> rst.Update
>> rst.Close
>>
>>I would like to include this code in an if statement

>that would first verify that there isn't already a
>recordset with those values to avoid duplicate entries.
>Could someone guide me a bit.
>>
>>Thanks
>>
>>Daniel
>>.
>>

>.
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I avoid duplicate entries? =?Utf-8?B?SmFuZQ==?= Microsoft Access Forms 11 16th Nov 2006 03:46 PM
How to avoid duplicate entries =?Utf-8?B?ci4gaG93ZWxs?= Microsoft Access Database Table Design 9 30th Nov 2005 08:28 PM
Avoid duplicate entries Allie Microsoft Access Database Table Design 2 1st Jul 2004 04:04 PM
RE: Avoid duplicate entries =?Utf-8?B?RGFuaWVsIFA=?= Microsoft Access VBA Modules 0 2nd Jun 2004 06:21 PM
Re: Avoid duplicate entries solex Microsoft Access VBA Modules 0 2nd Jun 2004 06:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:36 PM.