I have created a database (an address book) with Access, and I used the wizard in Access to create a query. I have put two textboxes on my form, 1 for First Name and 1 for Last Name where I can type in a persons name (either first or last), press a button ive called "find" and have it bring up that persons details from my database. The problem is is that I have read so many posts on various forums and articles etc and am totally confused and do not know where to start. Could somebody please give me some help as to where to start re coding these textboxes and my find button. I am using Visual Basic 2005 express edition.
'-----------------------------
Private Sub cmdFind_Click()
Dim fiNd2 As Variant
Adodc1.Refresh
If Text1.Text = "" Then ' this will check if the textbox1 is empty or not
' well if it is empty then this msgbox will appear and get out of the sub...
MsgBox "No value given for one or more required parameters", vbExclamation + vbOKOnly, ""
Exit Sub
Else
'this will put the text1.text into a container,,nothing i just want to put it there hahah,,
fiNd2 = Text1.Text
Adodc1.Refresh
Adodc1.RecordSource = "select * from Membership where FirstName like'" & fiNd2 & "%'"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount = 0 Then
' this will see if the database is empty if it is this what will happen...
MsgBox "Record Not Found"
Adodc1.Refresh
Exit Sub
Else
'if your app found the record it will now distribute all info from 0-3 fields...
Text2.Text = Adodc1.Recordset.Fields(0).Value
Text3.Text = Adodc1.Recordset.Fields(1).Value
Text4.Text = Adodc1.Recordset.Fields(2).Value
Text5.Text = Adodc1.Recordset.Fields(3).Value
End If
End If
End Sub
'------------------------------
oh i guess you already know how to put your database in an Adodc right? heheh.. thats all...
____________________________
-same thing over and over again..-
03-08-2006 at 05:02 PM
|
Gary Level: Sage Registered: 27-11-2005 Posts: 50
Re: Create Textbox for finding data in database
May I know how can I display each value in each textbox? Let say the table consists of:
xxxxx1 abc
xxxxx2 123
xxxxx3 def
"xxxxx1 abc" will be displayed in textbox1
"xxxxx2 123" will be displayed in textbox2
"xxxxx3 def" will be displayed in textbox3