|
-
Aug 26th, 2007, 01:22 PM
#1
Thread Starter
Fanatic Member
serch database
Ok, I have a Database in my app folder in a folder called database
the data base is called dtc and in it I have a table called Dtc
the table has 2 columns, DTC and Description
The DTC column is filled with Dtc numbers like P0001 P0002 etc and the description gives a description of each Dtc
On my frmDtcSearch form I have a listview called lvDtcSearch
A command button called cmdDtcSearch
A textbox called txtDtcSearch
and ADODC1
I am trying to make it so when I type in lets say P0301, and click button it will search database, then add the search (P0301) and Description from database to the listview.
Can someone get me started with this?
Thanx
-
Aug 27th, 2007, 06:43 AM
#2
Re: serch database
I'm not real familiar with using bound data controls, but I think there is a Find method associated with it.
Try
Code:
Adodc1.Recordset.Find "P0301"
-
Aug 31st, 2007, 09:35 AM
#3
Thread Starter
Fanatic Member
Re: serch database
I have tried that but
"P0301" Variable not defined
-
Aug 31st, 2007, 12:10 PM
#4
Re: serch database
P0301 should not be a variable, it should be the thing that you are looking for.
-
Sep 20th, 2007, 05:50 PM
#5
Thread Starter
Fanatic Member
Re: serch database
Ok this is what I came up with
Code:
Private Sub cmdDtcSearch_Click()
Dim search As String
Dim Clientname As String
search = txtDtcSearch.Text
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "SELECT * from Dtc WHERE dtc LIKE '%" & search & "%'"
Adodc1.Refresh
Dim lCt As Long
lCt = hyperDtcSearch.Count
If Adodc1.Recordset.EOF Then
If txtDtcSearch.Text = "P0001" Then
txtDtcSearch.Text = ""
MsgBox "Input Valid Dtc (P****) in text box"
Else
hyperDtcSearch.ItemAdd lCt, "", txtDtcSearch.Text, 6, 3
hyperDtcSearch.SubItemsAdd lCt, 1, "No Matching DTCs Found"
End If
Else
Adodc1.Recordset.MoveFirst
End If
Do Until Adodc1.Recordset.EOF
hyperDtcSearch.ItemAdd lCt, "", Adodc1.Recordset.Fields(0), 6, 3
hyperDtcSearch.SubItemsAdd lCt, 1, Adodc1.Recordset.Fields(1)
Adodc1.Recordset.MoveNext
Loop
If Adodc1.Recordset.EOF And Adodc1.Recordset.RecordCount > 1 Then
MsgBox "Records Found"
End If
End Sub
The only issue I am having is with this line
txtDtcSearch.Text = ""
How do I tell if the text box is empty?
thanx
-
Sep 21st, 2007, 05:58 AM
#6
Re: serch database
Code:
'two ways
If txtDtcSearch.Text = vbNullString Then
Msgbox "Nothing to search for"
End If
'or check the reverse
If txtDtcSearch.Text <> vbNullString Then
'place search code here
Else
Msgbox "Nothing to search for"
End If
-
Sep 21st, 2007, 05:44 PM
#7
Thread Starter
Fanatic Member
Re: serch database
Code:
If txtDtcSearch.Text = vbNullString Then
thank you very much,
Now how would I check if the textbox has 5 characters in it
(P0000 etc)
-
Sep 22nd, 2007, 01:07 PM
#8
Re: serch database
vb Code:
If Len(Trim(txtDtcSearch.Text)) = 5 Then
MsgBox "txtDtcSearch is having 5 characters in it"
End If
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Sep 24th, 2007, 07:24 AM
#9
Re: serch database
 Originally Posted by ganeshmoorthy
vb Code:
If Len(Trim(txtDtcSearch.Text)) = 5 Then
MsgBox "txtDtcSearch is having 5 characters in it"
End If
And I would put this in the Change event so that it would fire each time a change was made.
-
Sep 24th, 2007, 08:08 AM
#10
Frenzied Member
Re: serch database
 Originally Posted by Hack
And I would put this in the Change event so that it would fire each time a change was made.
How about Validate event?
-
Sep 24th, 2007, 08:11 AM
#11
Re: serch database
Change will fire instantly. Validate will fire when it loses focus.
-
Sep 24th, 2007, 08:26 AM
#12
Frenzied Member
Re: serch database
Oh yeah, thats right, I thought OP wanted to validate if there is 5 characters. My mistake. Sorry
-
Sep 24th, 2007, 08:32 AM
#13
Re: serch database
 Originally Posted by zeezee
Oh yeah, thats right, I thought OP wanted to validate if there is 5 characters. My mistake. Sorry 
No reason to be sorry. He does want to validate that. It is just a matter of the best place to put the validation code. You could use the validate event, and it would work. I just think that knowing instantly would be preferable to knowing after the fact.
However, in some cases, because of application requirements, my approach doesn't work, and yours would.
We are all about options. Let the OP decide which way he wants to go.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|