The code i have written (in VB)is :


Dim dbMyDB As Database
Dim rsMyRS As Recordset

Private Sub cmd_Delete_Click()
rsMyRS.Delete
userlist.RemoveItem userlist.ListIndex
End Sub

Private Sub cmd_Display_Click()
Set rsMyRS = dbMyDB.OpenRecordset("PC_User_Details", dbOpenDynaset)
rsMyRS.MoveFirst
If nm_txt.Text = rsMyRS!Name Then
If rsMyRS.RecordCount > 0 Then
name_txt.Text = rsMyRS!Name
ip_txt.Text = rsMyRS!ip
pass_txt.Text = rsMyRS!Password
dept_txt.Text = rsMyRS!department
ext_txt.Text = rsMyRS!extension
user_name.Text = rsMyRS!User
Else: MsgBox "The Name doen't Exists!!", vbOKOnly + vbCritical, "Invalid Record"
End If
Else: MsgBox "There are no Records in the DataBase!!", vbOKOnly + vbCritical, "No Information"
End If
rsMyRS.MoveNext
End Sub

Private Sub cmd_Exit_Click()
End
End Sub

Private Sub Form_Load()
Set dbMyDB = OpenDatabase("Users.mdb")
Set rsMyRS = dbMyDB.OpenRecordset("PC_User_Details", dbOpenDynaset)
If Not rsMyRS.EOF Then rsMyRS.MoveFirst
Do While Not rsMyRS.EOF
userlist.AddItem rsMyRS!Name

rsMyRS.MoveNext
Loop

End Sub

Private Sub userlist_DblClick()

Set rsMyRS = dbMyDB.OpenRecordset("PC_User_Details", dbOpenDynaset)

name_txt.Text = rsMyRS!Name
ip_txt.Text = rsMyRS!ip
pass_txt.Text = rsMyRS!Password
dept_txt.Text = rsMyRS!department
ext_txt.Text = rsMyRS!extension
user_name.Text = rsMyRS!User
End Sub

What do you want to the code? you did not stated what the problem is, try to state the problem in your code so that we can help you. I see in your code that you're trying to display the data from the database without specific given value therefor the data that will display is the first record, if... the table is not empty and, hence, you put a movenext command the next record will be displayed. if you want to display a specific record try to have specify the data you want to display.

i.e.
Set rsMyRs = dbMyDB.OpenRecordset("SELECT * from [PC_table] where fieldname='" & txtPCDescription.Text & "'")
If not rsMyRs.BOF Then
txtPCNum=rsMyRs!PCNum
....and so on
Else
Msgbox "Record not found.",vbInformation
End if

hi jireh,
thnx alot for ur solution.I really appreciate ur help.
well i want to develope a project wherein , whenevr a user "double-clicks" on any user in the list, the corresponding details such as user_name, password,IP address etc shud be displayed appropriately for that user.
The problem with my code is that , whenver i click on anyuser in the list, i get the details for the first user only.if i click on any other user, i get the details of the first user!! :-)
well i m new to visual basic and i wud really appreciate any ones help in solving this problem.
thank u in advance.

Have you tried my code I've given to you? I think that's excatly what you needed...

Yea, i did try your code...but i get a error message saying "Too Few Parameters . Expected 1"

i Used the following:


Private Sub userlist_DblClick()


Set rsMyRS = dbMyDB.OpenRecordset("SELECT * from [PC_User_details]where fieldname=' & user & ' ")
If Not rsMyRS.BOF Then

name_txt.Text = rsMyRS!Name
ip_txt.Text = rsMyRS!ip
pass_txt.Text = rsMyRS!Password
dept_txt.Text = rsMyRS!department
ext_txt.Text = rsMyRS!extension
user_name.Text = rsMyRS!User
rsMyRS.MoveNext
Else
MsgBox "Record not found.", vbInformation

End If
End Sub


where "user " is a Primary Key in the database "PC_User_Details".

please check the snap shot of my interface

thank u once again.

Ok try to use this code...

Private Sub userlist_DblClick()

Set rsMyRS = dbMyDB.OpenRecordset("select * [PC_User_Details] where user='" & userlist.Text & "')
If not rsMyRS.BOF Then
name_txt.Text = rsMyRS!Name
ip_txt.Text = rsMyRS!ip
pass_txt.Text = rsMyRS!Password
dept_txt.Text = rsMyRS!department
ext_txt.Text = rsMyRS!extension
user_name.Text = rsMyRS!User
End Sub
End Sub

I used the code u gave me as it is... and again i got an error message.
i might be making some stupid mistake but i m new to Visual Basic..ur help is highly appreciated.
the snap shot is attached.
thanks once again!

Set rsMyRS = dbMyDB.OpenRecordset("SELECT * from [PC_User_details]where fieldname=' & user & ' ")
If Not rsMyRS.BOF Then

it's not fieldname what i mean is the you replace that with the fieldname you want to search... i.e. user or username, I mean use the fieldnames in your table not the word fieldname

I used the code u gave me as it is... and again i got an error message.
i might be making some stupid mistake but i m new to Visual Basic..ur help is highly appreciated.
the snap shot is attached.
thanks once again!

Oh! just paste this code in the listbox...

Set rsMyRS = dbMyDB.OpenRecordset("select * [PC_User_Details] where user='" & userlist.Text & "')
If not rsMyRS.BOF Then
name_txt.Text = rsMyRS!Name
ip_txt.Text = rsMyRS!ip
pass_txt.Text = rsMyRS!Password
dept_txt.Text = rsMyRS!department
ext_txt.Text = rsMyRS!extension
user_name.Text = rsMyRS!User
End Sub

:sad: The same error again! m really goin crazy! i know that i m makin some stupid mistake. well heres the code for ur reference.

Private Sub Form_Load()
Set dbMyDB = OpenDatabase("C:\Documents and Settings\PC_User_Details_db.mdb")

Set rsMyRS = dbMyDB.OpenRecordset("PC_User_Details", dbOpenDynaset)

If Not rsMyRS.EOF Then rsMyRS.MoveFirst
Do While Not rsMyRS.EOF
userlist.AddItem rsMyRS!User

rsMyRS.MoveNext
Loop

End Sub


Private Sub userlist_DblClick()


Set rsMyRS = dbMyDB.OpenRecordset("select * [PC_User_Details] where User=" & userlist.Text & "")
If Not rsMyRS.BOF Then
name_txt.Text = rsMyRS!Name
ip_txt.Text = rsMyRS!ip
pass_txt.Text = rsMyRS!Password
dept_txt.Text = rsMyRS!department
ext_txt.Text = rsMyRS!extension
user_name.Text = rsMyRS!User


End If
end sub


User is a Primary Key for my PC_User_Details database.


I seriously dont know wotz wrong......
thnx in advance

Set rsMyRS = dbMyDB.OpenRecordset("select * [PC_User_Details] where Name='" & userlist.Text & "'")

I tried all the combinations with the " or and ' !! :confused:

Private Sub Form_Load()
Set dbMyDB = OpenDatabase("C:\Documents and Settings\PC_User_Details_db.mdb")

Set rsMyRS = dbMyDB.OpenRecordset("PC_User_Details", dbOpenDynaset)

If Not rsMyRS.EOF Then rsMyRS.MoveFirst
Do While Not rsMyRS.EOF
userlist.AddItem rsMyRS!User

rsMyRS.MoveNext
Loop

End Sub

No End If

Private Sub userlist_DblClick()

Set rsMyRS = dbMyDB.OpenRecordset("select * [PC_User_Details] where User=" & userlist.Text & "")
If Not rsMyRS.BOF Then
name_txt.Text = rsMyRS!Name
ip_txt.Text = rsMyRS!ip
pass_txt.Text = rsMyRS!Password
dept_txt.Text = rsMyRS!department
ext_txt.Text = rsMyRS!extension
user_name.Text = rsMyRS!User
End If
end sub

In this query put a single quote in your criteria where User=" & userlist.Text & "" I thinks that's the error because if the datatype of the field is string or text then you must put a single quote because if double quote it mean your criteria is a number, therefor put this in your criteria expression
Set rsMyRS = dbMyDB.OpenRecordset("select * [PC_User_Details] where user=' " & userlist.Text & " ' ")


User is a Primary Key for my PC_User_Details database.
There's no problem in primary key because primary key is use when you dont want to your data to be redundant or repeative.

Hi Jireh,
Thanx alot for ur help! But ..m gettin the same error :Syntax error.....(Missing operator)

I know u must been really pissed-off with me...but i m really looking forward for your solution!

I'll give it a last try...
Thnx

This is the design of my Table : PC_User_Details

User : Text
Name:Text
IP:Text
password :text
bios:text
extension :text

Can i have ur email id ? coz itried attachin the files but theres some problem

please recheck the path to the database and also the table name...i have modified them as i m workin on a company project!

where's the form? its only a project and an Access there's no form here I can't edit the code you know...

Hi Dreamboy,

Where is "FROM" keyword in ur SQL Statement.
Check this :


Set rsMyRS = dbMyDB.OpenRecordset("select * From [PC_User_Details] where Name='" & userlist.Text & "'")

Regards
Veena

hey veena

thnx alot! i had made such a silly mistake and it just didnt strike me.... neways i highly appreciate ur help.
thnx alot !

dreamerboy

I would request all of you to enclose your code in code tags so that it looks like code and not some vedic mantra. Please read this.

hi itz giving me an error "type mismatch"
at db.openrecordset("select * from table_name")

Hi Guru,

U have to declare a "RecordSet" Object.

Check this:
Dim RST As RecordSet
Set RST = Db.OpenRecordset("Select * From table_Name")

Regards
Veena

This question has already been answered. Start a new discussion instead.