Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Prevent Combobox Duplicates


I know how to search both a listbox and a combo box for duplicate entries and remove them.

What I would like to do is prevent a duplicate from ever getting entered in the first place.

How would I do that?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
How To Prevent Duplicates In Listview
Hello to all,

Here is my lookup in a Listbox.
Search by LastName
--------------------
CustID / LastName / FirstName / Contact / Phone
1 Don Joe Phillip 345-4335

Now, I populate my ListView when I click the Save button.


ListView
--------------------
CustID / LastName / FirstName / Contact / Phone
1 Don Joe Phillip 345-4335
1 Don Joe Phillip 345-4335 (Invalid)

I don't want to enter a duplicate in the listview. How do you prevent this from happening.

thanks

Prevent Duplicates In Combo
Ok, I am loading data to a form from an AccessDB via ADODB. While I am only displaying the first record, I want to populate a couple of Combo boxs also.
Code:
rsTable.Open "SELECT * FROM Table ORDER BY ID", CN,adOpenForwardOnly, adLockReadOnly
txtID = rsTable!ID
txtText1 = rsTable!Text1
etc

Do While Not rsTable.EOF
cboFName = rsTable!FName
cboSurname = rsTable!Surname
etc
rsTable.MoveNext
Loop

However this is causing duplicate entries in my Combo boxes, if there is more than one "Ann" in the database. Will have have to open a separate DISTINCT recordset to populate the combo boxes, or can I just check if "Ann" is already in the Combo?

Thanks in advance

Prevent Duplicates In Listview?
Ive been searchinf for like 30 minutes, and im wondering, how do you not allow dups into a listview? I only found removing after, and i want the api method that i saw quite a few months ago but cant seem to find (by martinliss?)

Prevent Specific Duplicates?
I know this prevents you from typing letters
VB Code:
If KeyAscii < Asc(".0") Or KeyAscii > Asc("9") Then KeyAscii = 0   ' Cancel the character. End If

but is it possible to do the following...
allow a user to type in a number such as 1.53 and only use one period?

Prevent Duplicates Using A Data Control
Is there a way to prevent a duplicate record from being saved using the MS Data control? If not is it possible to do it using ADODB and how?

The only way I've seen is using DAO and im not really sure how to do that.

Prevent Duplicates Data Save To Access Table
hi,please help.how to prevent duplicates data save to access table??

for example:
i want to prevent EmployeeName and OvertimeDate duplicate entries to the table.

thanks for help!

Prevent Duplicates Data Save To Access Table
please don't cross-post
Discussion continued here: http://www.vbcity.com/forums/topic.asp?tid=151672


hi,how to prevent duplicates data save to access table??below is the current code,when run the code have error message index out of bounds.

for example:
i want to prevent EmployeeName and OvertimeDate duplicate entries to the table.

this is the current code:
Code:Private Sub Command1_Click()
      Dim ADOCn As ADODB.Connection
      Dim ConnString As String
      Dim adoRS As ADODB.Recordset
      Dim sSQL As String
   
      ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & _
                         "Overtime.mdb;Persist Security Info=False"
      
      
      Set ADOCn = New ADODB.Connection
      ADOCn.ConnectionString = ConnString
      ADOCn.Open ConnString
  
      Set adoRS = New ADODB.Recordset
      sSQL = "SELECT EmployeeName,OvertimeDate FROM Temp"
      sSQL = sSQL & "WHERE EmployeeName = '" & ListView1.ListItems(2) & "' "
      sSQL = sSQL & "AND OvertimeDate= '" & ListView1.ListItems(7) & "' "
      
  
      adoRS.Open sSQL, ADOCn, adOpenStatic
      If adoRS.RecordCount > 0 Then
         MsgBox "Record for this person already exists"
         Exit Sub
      End If
  
      adoRS.Close
  
      Set adoRS = Nothing
  
      'write code here to add the record if is doesn't exist

      End Sub

thanks for help!



Edited by - bednarjm on 12/27/2007 11:07:14 AM

Filling A Combobox From Database But I Don't Want Duplicates In Th Combobox.
I want to output the contents of a database field (ms access) to a combobox but the field has many duplicates that I wish not to display. I just want one of each. Thanks

Getting Rid Of Duplicates In ComboBOX
Alright, in my Database I have many samples that are frozen on different dates.

What I'm trying to do is create a combo box with all the dates included. And when a date is selected, display all the samples that were frozen on that date in a listbox.

However, I've run into a problem already in that when I choose to make the combo box from the date column of my table, it takes all the dates, even the duplicates. For example, if there are 3 samples frozen on june 20th. there will be 3 june 20th's in the combo box. How can I get rid of this. I tried the removeitem property but it's not working. It says I'm not able to use this property when the combo box is connected to a data table or something when I go to help. ANY SUGGESTIONS?

Thanks.

Getting Rid Of Duplicates In Combobox
Hi
Well, the title says it all.
I am populating a combobox with the content of a table.
I would like to get rid of all the duplicate entries in my combobox.
Is there a simple way to do so ?
Thanx

Duplicates In Combobox
is there a property in combobox that excludes the possibility of duplicates in the list, i've checked but in vain!! for the moment i'm using a loop to check and then i add... but it's **** slow!!!

I'll be among the best soon, very soon!!!

Combobox Duplicates After Save...
I have a combobox that is populated with the code below. When the program is first run, the combobox doesn't have duplicates, but after a save is made, it will duplicate each entry once. I'm sure it's something easy I'm missing, I just haven't found it, yet.


Code:
rs.Open "SELECT DISTINCT VENDOR_ID FROM RECEIVING_INSPECTION", conn, adOpenKeyset
If rs.RecordCount > 0 Then
rs.MoveFirst
Do While rs.EOF = False
cmbVendor.AddItem rs!VENDOR_ID
rs.MoveNext
Loop
End If

Remove Duplicates In Combobox
i have a combobox that displays the values in my field.....


field: Food
values: cookies, apple, spaghetti, chocolates, cookies

i want to remove the duplicates from showing in the combobox. (but it should be still in my database...) i just want to remove or disable it from showing because it is unnecessary for the user....

please help me out... thanks...

Remove Duplicates From ComboBox
Ok my combo boxes get filled using a database on formload.

Is there a way to see if something is already in the combo box therefore not adding it again ? (Assuming this would be slow?)

or does anyone have a quick function to remove duplicates?

Checking For Duplicates In Combobox History...
Hi...

I have a combo box which stores the history of folder paths i've browsed to. I have no problems adding paths to a combo box, I just can't get my brain around the code for checking for duplicates...I tried searching the vbCity for an answer to no avail...

This is my code...It doesn't work, because it only checks the current value in the string, not the entire combo box contents:

Code:cboPath.Text = strPathVar
For i = 0 To cboPath.ListCount - 1
    If cboPath.List(i) <> strPathVar Then
       cboPath.AddItem strPathVar
    Else
       'Do nothing
    End If
Next

Thanx in advance...



Edited by - D-Race on 8/14/2005 6:26:28 AM

Prevent Changes To A ComboBox
I have a form with a combo box that has 8 items for the user to select from. I want to be sure that the user does not make any entry other then these 8 items.

I tried the Lock property but while the combo box can be scrolled no item can be selected. Any suggestions as to how I can set the combo box to reject attempts to enter invalid items?

VBA ComboBox Prevent Additions
When using ComboBox in a UserForm with VBA, can you prevent the user from inputing data into the list so that they can only pick from what is in the list? How do you do that?

Thanks

Prevent From Writing Into Combobox
How do i prevent a user from typing stuff into a combobox? (so that they must select sumthing thats already in there?)

Prevent Entry To ComboBox
is it possible to prevent the user from entering data into a combo box?

Prevent Combobox Dropdown When Locked
How can I prevent the Combobox's Dropdown when the combobox's Lock Property is set to True? I don't want to set Enable to False because I want the ForeColor to appear in Blue.

Thanks

Mark

Prevent Combobox From Selecting An Option
Hi,

Is there a way to disable the functionality where the combobox will move to the first selection in the list that starts with the letter that the user has pressed in the text portion of the drop-down? I need to override this functionality myself. Not sure how best to do that.

Thx.

RESOLVED Prevent From Typing In Combobox
Hello

How can I prevent users from typing in a combobox in Excel?

thanks

Walter



Edited by - Nunuwawa on 10/19/2006 3:29:50 AM

Sum For Duplicates
Hello.
I have a table in a format like

Name Task Week Revenue
Jim Typing 2 17
Jim Dashboard 2 11
Jim Dashboard 2 7
Jim Dashboard 3 5
Cathy Copying 3 4
Bobby Typing 2 11
Bobby Typing 2 6

I need to sum column4 for everything where the previous 3 records are identical

Name Task Week Revenue
Jim Typing 2 17
Jim Dashboard 2 18
Jim Dashboard 3 5
Cathy Copying 3 4
Bobby Typing 2 17

Should this be done through find dplicate query, or how ?

Duplicates?
Does any one have a good link or easy way to find duplicates in a column (1000+ rows) ? The items that are duplicated in the column have numbers and text.

jbp53

Duplicates
G'day all,

Is there a way to decipher duplicates in a listbox?? And from this is there a way to set a labels caption as the amount of duplicates found. I realise this may be difficult but I am sure it is not difficult and I am kinda new to Visual Basic.


Thanks in advance for your help,

~Jordan

Duplicates
If I created a form with 2 listviews with sepreate entries :

LV1 LV2
----- -------
RED GREEN
BLUE YELLOW
WHITE BLACK
CYAN PINK

When it loads, LV1 populates a list of items. Then I have LV2 populate its own list of itmes running off of a timer.

Is there a way for the form to notify if there are duplicate items between 2 listviews when LV2 populates with a message box or another form? And if so how do I code it?

No Duplicates
I'm having problems with checking for duplicate date and time in a database through vb. I don't want same date and time duplicated.

Explanation:

This program is to keep a persons meetings information so I don't want that person or someone else to be able to have the same date and time of someone elses meetings.

Duplicates
I need to find all duplicates in a particular field but I have two tables (year 2000) and (year 2001). How can i query both tables at the same time for duplicates. For example one may be in year 2000 table and the other in the year 2001 table

thank you

Duplicates
I have a table with two fields "vin1" and "vin2"
I need to see if their are any duplicates between the two fields.

Thank you
Harley

Duplicates Once More
Hi all,
I've been reading thru a couple of threads and it was very interesting but I still dont know why this wont work

Code:
SELECT *
FROM rfs_Desktops_Laptops
WHERE Machin_Name = (SELECT DISTINCT Machin_Name FROM rfs_Desktops_Laptops)
let alone

Code:
SELECT *
FROM rfs_Desktops_Laptops
WHERE Machin_Name = (SELECT DISTINCT Machin_Name FROM rfs_Desktops_Laptops)
GROUP BY Machin_Name
basical this is a query against a ugly fact table in a SQL DB. I wouldnt mind deleting those dubs straight away but displaying would be nice to start with.

Mike

No Duplicates..
Hello....
I'm using this code so that whenever an item is added to the listbox, it checks to see if it exists using this code:


VB Code:
Sub NoDups(lst As listbox, Str As String)On Error Resume Next    Dim tf As Boolean    Dim X     If lst.ListCount = 0 And Str <> "" Then        lst.AddItem Str    Else        tf = False        For X = 0 To lst.ListCount - 1            If lst.List(X) <> Str Then                tf = False            Else                tf = True                Exit For            End If        Next X        If tf = False And Str <> "" Then            lst.AddItem Str        End If    End IfEnd Sub


The problem is, sometimes it STILL allows duplicates to get in, and, sometimes it doesn't allow non-duplicates to get in....... anyone see anything in there that should be fixed..or would make it very unaccurate?

Duplicates
Morning,
This code works fine, but if there is a duplicate title it will also delete it. Is there any way to delete one record at a time?

Dim strSQL As String
strSQL = "DELETE FROM BLSOLD "
strSQL = strSQL & "Where TITLE = '" & frmOrder.txtTitle.Text & "'"
If MsgBox("Are you sure you want to delete this record?", _
vbYesNo + vbQuestion, "Delete") = vbYes Then
cn.Execute strSQL
End If

Thanks.

Duplicates
Ive seen progs before where you load a wordlist and press a button and it will remove all the duplicates in the list.WHat would the code be for finding the dupes and eleting them.Thx yall i love tha help

Duplicates
I need help in validating duplicates that are already in a list box; if the user types the same name in the text box, i need it to not allow the duplicate to go in. can anyone help me?

Why Am I Getting Duplicates?
I've searched the forum and saw some great ideas for randomizing and storing arrays. I've got some code but some reason I'll get at least one set of back-to-back duplicates. This happens 9 times out of ten.


VB Code:
Public Sub RandSquares()Dim TempSquare As IntegerDim LastSquare As IntegerDim SquarePosition As IntegerDim iloop, temptext  For iloop = 0 To 48Randomize'Pick random position in array of diminishing sizeSquarePosition = (Rnd * (49 - iloop)) + 1'Store Temporary positionTempSquare = NumofSquares(SquarePosition)'Store position in sequenceRandSequence(iloop + 1) = TempSquare'Get last element in arrayLastSquare = NumofSquares(49 - iloop)'Move temporary position to last elementNumofSquares(49 - iloop) = TempSquare'Replace current position with last elementNumofSquares(SquarePosition) = LastSquaretemptext = temptext & iloop + 1 & "=" & RandSequence(iloop + 1) & vbCrNext iloopMsgBox temptextEnd Sub

Any Ideas? Am I missing something obvious?

How Can I Get Rid Of Duplicates??
Hi again all,
Just wondering how I can get rid of duplicates returned by a function that show up in a combo box?

I have this showing up:

\Comp1
\Comp1
\Comp2
\Comp1
\Comp2
\Comp2
\Comp2
\Comp1

This I don't want...

This however is what I do want.....

\Comp1
\Comp2

(Does not matter which order)

So does anyone have a clue how to do this?

Thank you very much!! :P

Scott

Duplicates
In the below example, if I don't issue a 10 second pause after the delete query and attempt to add data w/o this pause, I get duplicate entries.  It's like SQL Server isn't finished deleting data when I attempt to append.  Am I doing something wrong?

Thanks,
CJ



dbConn.Open DE.fatsales_SQL.ConnectionString
    
    dbConn.Execute "DELETE FROM " & strTableName & " WHERE " & strTableName & _
      ".StoreCode = '" & strStoreCode & "' AND " & strTableName & ".Date >= #" & _
      Format(startDate, "mm/dd/yyyy") & "# AND " & strTableName & ".Date <= #" & _
      Format(endDate, "mm/dd/yyyy") & "#"
      
    GlobalAccess.addServiceHistory "Command issued at - " & Format(Now, "hh:mm:ss")
    
    frmService.txtCmdStatus.Text = dbConn.State
    
    While dbConn.State = adStateExecuting Or _
      dbConn.State = adStateConnecting Or _
      dbConn.State = adStateFetching
    
      frmService.txtCmdStatus.Text = dbConn.State
    Wend
    
    frmService.txtCmdStatus.Text = dbConn.State
    
    GlobalAccess.addServiceHistory "Command completed at - " & Format(Now, "hh:mm:ss")
      
    dbConn.Close
    
    GlobalAccess.addDbHistory _
      strStoreCode, _
      "Microsoft Access database (*.mdb) delete; table: " & strTableName & _
      ", store code: " & strStoreCode & ", start date: " & startDate & _
      ", end date: " & endDate
      
    GlobalAccess.addServiceHistory _
      "(tbl: " & strTableName & ") Pause to allow cached data to flush; 10 secs."
    
    startTime = Now
    While Utils.wait(startTime, 10) = True
    Wend

No Duplicates
I am making an inventory system using adodb codings with unique item codes. I tried to make a looping anf select funtions to prevent updating uplicate item codes once the user clicked update. At first it works but when i tried for the 2nd time it accepts duplication.Can somebody teach how to correct this code or if you can modify it I am very much honored:

Private Sub cmd_dsave_Click()


Select Case drs.Fields("DEALER ID")

Case Is <> txt_dealerid.Text
    
   If MsgBox("Save New Dealer's Information?", vbInformation + vbOKCancel) = vbOK Then
    
    With drs
    .AddNew
    .Fields("DEALER ID") = txt_dealerid.Text
    .Fields("NAME") = txt_dealername.Text
    .Fields("AGE") = txt_dealerage.Text
    .Fields("SEX") = cbo_dealersex.Text
    .Fields("ADDRESS") = txt_dealeraddress.Text
    .Fields("TEL#") = txt_dealertel.Text
    .Fields("MOBILE#") = txt_dealermobile.Text
    .Fields("TERMS OF SERVICE") = txt_dealerterms.Text
    .Fields("DISCOUNT") = txt_dealerdiscount.Text
   
   .Update

    
    End With
    
    End If
    
Case Is = txt_dealerid.Text
    
    MsgBox "NO DUPLICATES", vbInformation
    cmd_dprev.SetFocus

End Select

Yes To Duplicates
is there any way that i can add duplicates in a record?
by the way,my program contains a frmAdd where user adds in a task and its description, and this gets stored in the database. Looks like when i add a task with the same name but different descriptions, my program seems to read in both tasks as the same one, and completely ignores the other one!

Help With Duplicates
I apologize if this is a common question, but I tried to look in FAQ, but came up empty. I have an array of a UDT. The type, MyType, has 4 fields. What I am trying to do is come up with a list/array of all the possible values of one of the fields, without any duplicates. Any help with this would be greatly appreciated. Thanks.

No Duplicates
Using the code below, what code would I have to add in order to ensure that an item is added only one time? (if I already added it to the second list and tried to add it again using the command button, an error msg should pop up) Thank you.

private Sub cmdAdd_Click()
Dim i as Integer
for i = 0 to List1.ListCount - 1
If List1.Selected(i) = true then List2.AddItem List1.List(i)
End If
next
End Sub

private Sub Form_Load()
Dim aLine as string
Open App.Path & "grocery.txt" for input as #1 Do While Not EOF(1)
Line input #1, aLine
List1.AddItem aLine
Loop
Close #1
End Sub




Archie Kantzavelos

Getting Rid Of Duplicates In Combo Box
Alright, in my Database I have many samples that are frozen on different dates.

What I'm trying to do is create a combo box with all the dates included. And when a date is selected, display all the samples that were frozen on that date in a listbox.

However, I've run into a problem already in that when I choose to make the combo box from the date column of my table, it takes all the dates, even the duplicates. For example, if there are 3 samples frozen on june 20th. there will be 3 june 20th's in the combo box. How can I get rid of this. I tried the removeitem property but it's not working. It says I'm not able to use this property when the combo box is connected to a data table or something when I go to help. ANY SUGGESTIONS?

Thanks.

Checking For Duplicates
Hi,
I'm making a program in vb that will send data from a text file into an MS Access table. Now my problem is that if a record is a duplicate in my file the program with get an error from Access and stop completly even if the next record to be added is not a duplicate. Is there a way to check id theres a duplicate in a my table first and only add a new record if its not a duplicate. I tried to use a if statement but i cant get it to work

Code:
Open "C:/My Documents/project/load.txt" For Input As #LoadFile
Do Until EOF(LoadFile)
dup = ""
Input #LoadFile, Load, Loc_City, Loc_State, Dest_City, Dest_State, Desc, Req, Dte
Connection.Execute ("Select Load_ID INTO dup from tblLoads Where Load_ID = '" & Load & "'")
If dup = "" Then
sql = "INSERT INTO tblLoads VALUES('" & Load & "','" & Loc_City & "','" & Loc_State & "','" & Dest_City & "','" & Dest_State & "','" & Desc & "','" & Req & "' ,'" & Dte & "')"
Connection.Execute (sql)
End If
Loop
IF anyone can help me please reply as soon as possible
Thanx
Steffy

Removing Duplicates?
Is there a way to remove duplicate records in access w/o manually pasting with the "structure only" option ?

I need to automatically detect and remove duplicate records everytime a report is opened.

Thank you all in advance. =]

Flagging Duplicates
I have an excel spreadsheet consisting of three columns
Column A is an account number, B and C a numerical value in each. I would like to place a flag in column D if there are repeats of the same numbers eg duplicates in column A.
I have been tying the following but it wont work. Does anyone have any ideas please?

=IF(COUNTIF(Range1,A2)>1,"Duplicate","")

In cell C1 is the title Range1. Cells A2 through C4000 are the named range Range 1


many thanks

Delete Duplicates
I use vba to create a table,,, and that table sometimes has some duplicate enties. How do i delete those duplicates... thanks!

Prohibiting Duplicates
Does anyone know if there is a way to format individual columns in a speadsheet to prohibit duplicate entries in the column?

Copyright 2005-08 www.BigResource.com, All rights reserved