4 Replies - 2988 Views - Last Post: 03 August 2011 - 09:55 AM Rate Topic: -----

#1 pathllk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 26-July 11

How Search Database using Inputbox

Posted 26 July 2011 - 11:10 AM

Dear all I working with a project that created in VB6. I use MS Access 1997 as database and connect the database with VB6 using adodb connection. I am new i VB6 programming. I use a listview control to view the records. My database have a column "SEQURITY_NAME". Now I want to search a SEQURITY_NAMES using a inputbox from the database and also want to display the search result in the listview control.

I am using these commands in my project:-

 
Dim CON As New ADODB.Connection
Dim RS As New ADODB.Recordset

Private Sub Command1_Click()
With RS
.AddNew
!Date = Text1.Text
!SEQURITY_NAME = Text2.Text
!d_open = Text3.Text
!d_high = Text4.Text
!D_LOw = Text5.Text
!d_close = Text6.Text
!p_close = Text7.Text
!d_p_l = Text8.Text
.Update
End With
End Sub



Private Sub Form_Load()
CON.Open ("provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "\DB1.mdb")
RS.Open "select * from EQUITY", CON, adOpenDynamic, adLockOptimistic
Dim itm1 As ListItem
With RS
Do Until .EOF
Set itm1 = lv1.ListItems.Add(, , !Date & "")
itm1.SubItems(1) = !SEQURITY_NAME & ""
itm1.SubItems(2) = !d_open & ""
itm1.SubItems(3) = !d_high & ""
itm1.SubItems(4) = !D_LOw & ""
itm1.SubItems(5) = !d_close & ""
itm1.SubItems(6) = !p_close & ""
itm1.SubItems(7) = !d_p_l & ""
.MoveNext
Loop
Set itm1 = Nothing
End With
End Sub

Private Sub lv1_DblClick()
Text1.Text = lv1.SelectedItem.Text
Text2.Text = lv1.SelectedItem.SubItems(1)
Text3.Text = lv1.SelectedItem.SubItems(2)
Text4.Text = lv1.SelectedItem.SubItems(3)
Text5.Text = lv1.SelectedItem.SubItems(4)
Text6.Text = lv1.SelectedItem.SubItems(5)
Text7.Text = lv1.SelectedItem.SubItems(6)
Text8.Text = lv1.SelectedItem.SubItems(7)
End Sub

Private Sub Text7_Change()
Text8.Text = Val(Text7) - Val(Text6)
End Sub



Please friends help me regarding this.

Is This A Good Question/Topic? 0
  • +

Replies To: How Search Database using Inputbox

#2 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: How Search Database using Inputbox

Posted 29 July 2011 - 04:48 PM

Explain "inputbox from the database" please.
Was This Post Helpful? 0
  • +
  • -

#3 leixnt  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 30
  • Joined: 24-July 11

Re: How Search Database using Inputbox

Posted 02 August 2011 - 12:17 AM

dim src as string 'declare variable for text in input box

src = inputbox("Please enter name :","Enter Name")

if you type "example" in input box

then

src = "example" 'VARIABLE SRC CONTAIN TEXT FROM INPUT BOX

then use query to find name...
Was This Post Helpful? 0
  • +
  • -

#4 guyfromri  Icon User is offline

  • D.I.C Addict

Reputation: 46
  • View blog
  • Posts: 826
  • Joined: 16-September 09

Re: How Search Database using Inputbox

Posted 02 August 2011 - 09:33 AM

If you want to search a table for information how about

rs.movefirst
rs.findfirst "ColName='" & src & "'"



That would return the position of the first record with the matching name. If you have possible dup names, you could write it with a loop and rs.findnext same syntax..

Hope that helps :)
Was This Post Helpful? 0
  • +
  • -

#5 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: How Search Database using Inputbox

Posted 03 August 2011 - 09:55 AM

A good way to check for dup names is to use the Filter property: rs.Filter = "ColName='" & src & "'". Then you can check the RecordCount property to see how many records are in the filter. To release the filter, set the Filter property to "" or to vbFilterNone.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1