Hi.I am working on a project(patient management system).I want a code for this.
Once I enter the name of the patient whose details want to know, I want the next form to be loaded and those specific details of that particular patient(already stored in a database) to be displayed in a text box.
I use Vb6 and MS access

Recommended Answers

All 6 Replies

Try this:

Dim con as new ADODB.Connection
Dim rs As New ADODB.Recordset 


If txtSEARCH.Text = vbNullString Then
  MsgBox " The search field is empty.", vbExclamation 	'Change message if you want
  txtSERACH.SetFocus
End If

With rs

    If .State = adStateOpen Then .Close

    'TABLENAME - replace with your table name 
    'txtSEARCH - replace: name of your textbox where you enter the
    'patient name of the patient that records you want 
    
    .Open "Select * from TABLENAME where NAME =" & txtSEARCH.Text & ";", con, adOpenKeyset, adLockPessimistic
    
    
    Do While .EOF = False
    
    With Form5		'Change Form5 to the name of the form which to be loaded on click
    

    'Change "NAME" and "AGE" with your own Table Column names
    'from the table where the records are located 
    'Arrange them according to where textbox the records would be displayed

    .txtNAME.Text = rs.Fields("NAME").Value
    .txtAGE.Text = rs.Fields("AGE").Value
    .txtROOM.Text = rs.Fields("Roomnumber").Value
           

    End With

   .MoveNext
   Loop
  
  .Close

Form5.Show	'Change Form5 to the name of the form which to be loaded on click

Put this code on a Command Button - Click Event

Hope this helps :)

Abe, your statement is incorrect. The returned data is a string so you have to enclose it in hyphens -

.Open "Select * from TABLENAME where NAME = '" & txtSEARCH.Text & "'", con, adOpenKeyset, adLockPessimistic

:)

Oh, didn't see that one.:$

@Ashwin149, please mark this thread as solved found at the bottom of this page, thanks.:)

It has been open for some time now.

Hi.
I need another code where once I enter the name of a food item, I want the details of that food item to be displayed in a text box(Details stored in a database).THE PROBLEM IS I have to use a data control or do it by pure coding (I'm not allowed to use ADO.net)Pls give me the code for both

I then suggest that you have a look at THIS link. It gives you everything you need on the data control.

The code will be something like -

Text1.Text = "Apple"

datFood.Recordset.FindFirst "YourFoodFieldNameHere = " & Text1.Text
commented: I guess no one in your "home" forum gives you rep.... you've earned it. +6
commented: Thank you for helping us fight spam! +16
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.