473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Duplicate Values

Hi All,

Could anybody please help me.. Not sure if this was the right forum to post in but this has got to do with Databases so here goes..

Here's the scenario.
We are developing a program In Visual Basic which uses a Microsoft Access Database file to store information of our customers. We have enabled the Allow Duplicates value in the CustomerLastName field as we may have 2 customers with the same last name. Example Sam Edwards and Mike Edwards

Now when we search the database by the customers last name and type in Edwards, the listbox shows that there are two edwards in the database however, when we click the first Edwards it shows Sam Edwards and when we click the second Edwards it still only shows Sam Edwards. I have a feeling it has something to do with the rs.movefirst code as when we change the to rs.movenext it will show Mike Edwards but not Sam Edwards even changing this to rs.movenext makes other records cause this error message " No Current Record."

Am really stuck and would apprecaite anyone's input.

Thanks.
VBSourcer.
Aug 22 '06 #1
5 2696
MMcCarthy
14,534 Expert Mod 8TB
I'm not sure what you've done.

However, populating a Listbox in this way requires the following.

-----------------------------------------------

Dim strSQL As String

Me.ListX.RowSourceType = "Table/Query"

' I assume you get the value 'Edwards from somewhere but since I don't know where
strSQL = "SELECT ID, LastName, FirstName FROM tableName WHERE LastName='Edwards'"

Me.ListX.RowSource = strSQL
Me.ListX.ColumnCount = 3
Me.ListX.BoundColumn = 1
Me.ListX.ColumnWidths = "0 cm; 5 cm; 5 cm"

----------------------------------------

Something along these lines should populate your list correctly. Otherwise, something else is going on.



Hi All,

Could anybody please help me.. Not sure if this was the right forum to post in but this has got to do with Databases so here goes..

Here's the scenario.
We are developing a program In Visual Basic which uses a Microsoft Access Database file to store information of our customers. We have enabled the Allow Duplicates value in the CustomerLastName field as we may have 2 customers with the same last name. Example Sam Edwards and Mike Edwards

Now when we search the database by the customers last name and type in Edwards, the listbox shows that there are two edwards in the database however, when we click the first Edwards it shows Sam Edwards and when we click the second Edwards it still only shows Sam Edwards. I have a feeling it has something to do with the rs.movefirst code as when we change the to rs.movenext it will show Mike Edwards but not Sam Edwards even changing this to rs.movenext makes other records cause this error message " No Current Record."

Am really stuck and would apprecaite anyone's input.

Thanks.
VBSourcer.
Aug 22 '06 #2
Thank You for your prompt response.
We attain the value "Edwards" from our Last Name Search box and this works fine. But the problem is when we have 2 customers both with the last name Edwards
Example Sam Edwards and Mike Edwards

This works fine as the listbox displays all records with whatever last name we tried to search for in this example "Edwards"

But when we click the listbox to display the customer information it will only show the first Sam Edwards record. When we select the second Edwards name from the listbox it still only shows the first Sam Edwards Record. I have a feeling it might have something to do with the rs.movefirst as when this is changed to rs.movenext it will move to the next Edwards record but causes other records to display an error message "No Current Record" here's the code I use to list the data when the user clicks on the listbox

Private Sub lstdata1_Click()
On Error Resume Next
Set rs = Db.OpenRecordset("Select * from tbldata where CusLastName = '" & Trim(lstdata1.list(lstdata1.ListIndex)) & "'")
rs.MoveFirst
lblCardNo.Caption = "Loyalty Card Number: " & rs("GenNum")
txtFirstName.Text = rs("CusFirstName")
txtLastName.Text = rs("CusLastName")
txtPhone.Text = rs("CusPhone")
txtCell.Text = rs("CusCell")
txtEmail.Text = rs("CusEmail")
txtSuburb.Text = rs("CusSuburb")
txtJoined.Text = rs("JoinDate")
txtStamps.Text = rs("SpacesRem")
txtStaff.Text = rs("StaffID")
End Sub

Thanks..
Aug 22 '06 #3
P.S. I am not that advanced at programming but I do know a bit to get me around.
Aug 22 '06 #4
MMcCarthy
14,534 Expert Mod 8TB
You have used ListIndex incorrectly this defaults to the first item on the list regardless of selection.

Yours select statement (if the list was referenced correctly would return all customers whose last name is Edwards. Assuming that is what you want try the following. If you only want to return the selected customer you will need to include the customer ID in the list box as a hidden bound field (see example above).

To select all customers with last name edwards:

Private Sub lstdata1_Click()
On Error Resume Next
Set rs = Db.OpenRecordset("Select * from tbldata where CusLastName = '" & Trim(lstdata1.list(lstdata1.Value)) & "'")

rs.MoveFirst
Do until rs.EOF

'Your Code here ...

rs.MoveNext
Loop

End Sub

To select only one customer you will need a way to uniquely identify that customer. CusLastName will not do this.
Aug 22 '06 #5
Thank You again for your help,
I will try your code asap.
Will post reply to let you know how it goes.
Aug 23 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Mark | last post by:
When my form goes to a new record, I have a procedure that copies the last record added to the form's underlying table into the form. The intent is that a series of new records may have the same...
9
by: vbportal | last post by:
Hi, I would like to add BitArrays to an ArrayList and then remove any duplicates - can someone please help me forward. I seem to have (at leaset ;-) )2 problems/lack of understanding (see test...
4
by: sri2097 | last post by:
Hi all, I'm storing number of dictionary values into a file using the 'cPickle' module and then am retrieving it. The following is the code for it - # Code for storing the values in the file...
3
by: skennd | last post by:
Here's my problem in exact replication: I have used the find duplicate query in Access, and the query determined the following duplicate values by the following query: In (SELECT FROM As...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
4
by: FangQ | last post by:
hi I am very new to mysql. I have a question about using the "on duplicate update" clause with insert command. my table "data" has two columns, field1 and field2, where field1 is the index...
2
by: mavmavv | last post by:
I have a Form where I have created a duplicate record button, no problem... The subform is where my problem lies. The subform displays data matching the mainform's ID, these two values are...
3
by: rajeshkrsingh | last post by:
Hi friends, Step1- create table duplicate ( intId int, varName varchar(50) ) insert into duplicate(intId,varName) values(1,'rajesh') insert into duplicate(intId,varName) values(2,'raj12')...
2
by: raphael001 | last post by:
In my Visual Basic program I'm just trying to find duplicate values entered into an array from an inputbox, but i can't seem to get the coding right on the final part to check for duplicate values...
4
by: ramdil | last post by:
Hi All I have table and it have around 90000 records.Its primary key is autonumber field and it has also have date column and name, then some other columns Now i have problem with the table,as my...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.