Click to See Complete Forum and Search --> : Help on Access DB in VB


SgiGod
February 27th, 2000, 02:05 PM
I have a access DB called data1.mdb it has lots of fields in it like (First, Last, Address).

I would like to make a form that when i type the last name of some one in TextBox1 it would then search the DB and fill in (first in TextBox2 and Address in TextBox3)

I know must of it I Just don't know how to do a search. :)

Thanks in Advance
Donny S.

sriky
February 27th, 2000, 02:32 PM
This is one of the ways:

strFirst="select FirstName from data1.mdb where LastName =" & text1.text

text2.text = strFirst



What if there are 2 persons with the same last name?

may be, you can use a count and if count>1, pop up a message box

sriky
February 27th, 2000, 03:37 PM
sorry, it should be

select FirstName from tableName where LastName = "

You should open the connection obj and the recordset.

SgiGod
February 27th, 2000, 04:37 PM
Ok I got it to work but it won't update the DB when I change the text in a text box or on exit

Johnny101
February 27th, 2000, 04:38 PM
If the user will always have the exact name of the person they are looking for, then you can do as suggested above. But what if they dont know exactly how to spell the person's last name. Or they only enter the first few letters. Then you would have to search for wildcards.


sql = "SELECT * FROM TableName WHERE LastName LIKE '%" & txtLastName.Text & "%'"




The wildcard characters above are for SQL Server, you may have to try * instead of % for Access, I'm not sure about that.

You could have an option button on the search form: One for exact search and one for wildcard search to distinguish when to use the LIKE clause and when not to.

Good luck,
John

John Pirkey
MCSD
www.ShallowWaterSystems.com