search database show Results in mshflexgrid

Philmer
04-15-2004, 02:31 PM
I have a search form with this code. I can't seem to get the results to show in the mshflexgrid. Can anybody take a look at the code and tell me what I am doing wrong and how to fix it? :whoops:

Option Explicit

Private Sub cmdSearch_Click()
Dim strremarks As String, strfilename As String
Dim strremarksFound As String, strTitleFound As String
Dim intTotRecs As Integer
Dim i As Integer
Dim j As Integer

Dim Con1 As ADODB.Connection
Dim Rec1 As ADODB.Recordset

strremarks = txtremarks.Text
strfilename = txtfilename.Text

Set Rec1 = New ADODB.Recordset
Set Con1 = New ADODB.Connection
Con1.Open ("Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\unzipped\neee\Cd-Register\Data\cd.mdb")

If optremarks.Value = True Then
'use sql to search for artist in database
Rec1.Open "SELECT remarks, filename from docs WHERE remarks ='" & strremarks & "';", Con1, adOpenForwardOnly, adLockPessimistic
If Rec1.Fields(0) < 1 Then
i = MsgBox("No results found", vbOKOnly + vbInformation + vbApplicationModal, "CD Database Search - No Results")
Else
strremarksFound = Rec1.Fields("remarks") 'then the result assigned to var
strTitleFound = Rec1.Fields("filename")
i = MsgBox("Results: " & strremarksFound & " - " & strTitleFound, vbOKOnly + vbInformation, "CD Database - Search Results") 'display results
'the following is supposed to highlight the row with the result

search.Show
Rec1.Close
Rec1.Open ("SELECT * FROM docs ORDER BY filename")
Do While Not Rec1.EOF
intTotRecs = intTotRecs + 1
Rec1.MoveNext
Loop
Rec1.Close
search.MSHFlexGrid1.Row = 1
For i = 1 To i = intTotRecs
If search.MSHFlexGrid1.Text = strremarksFound Then
For j = 0 To 2 'Numbe of your columns
search.MSHFlexGrid1.Col = j
search.MSHFlexGrid1.CellBackColor = vbRed
Next j
End If
search.MSHFlexGrid1.Row = search.MSHFlexGrid1.Row + 1
Next i
Exit Sub
End If
ElseIf optfilename.Value = True Then
Rec1.Open "SELECT remarks, filename from docs WHERE remarks ='" & strremarks & "';", Con1, adOpenForwardOnly, adLockPessimistic
If Rec1.Fields("filename") < 1 Then
i = MsgBox("No results found", vbOKOnly + vbInformation + vbApplicationModal, "CD Database - No Search Results")
Else

strTitleFound = Rec1.Fields("filename")
strremarksFound = Rec1.Fields("remarks")
i = MsgBox("Results: " & strremarks & " - " & strfilename, vbOKOnly + vbInformation, "CD Database - Search Results")
Exit Sub
End If
End If
Set Rec1 = Nothing
Rec1.Close
Con1.Close

'after clicking ok in the msgbox displaying results, the search-dialog
'should be closed, and the artist selected in the flexgrid.

End Sub

Private Sub Form_Load()
optremarks.Value = True
txtfilename.Enabled = False
End Sub

Private Sub optArtist_Click()
txtfilename.Text = ""
txtremarks.Enabled = True
txtfilename.Enabled = False
txtremarks.BackColor = vbWhite
txtfilename.BackColor = vbMenuBar
End Sub

Private Sub optTitle_Click()
txtremarks.Text = ""
txtfilename.Enabled = True
txtremarks.Enabled = False
txtfilename.BackColor = vbWhite
txtremarks.BackColor = vbMenuBar
End Sub

Private Sub txtArtist_GotFocus()
txtremarks.SelStart = 0
txtremarks.SelLength = Len(txtArtist.Text)
End Sub

Private Sub txtTitle_GotFocus()
txtTfilename.SelStart = 0
txtfilename.SelLength = Len(txtTitle.Text)
End Sub

MKoslof
04-15-2004, 05:44 PM
You never actually set the datasource of the MSHFlexGrid. The MSHFlexGrid is a bound control, you need to use the Set DataSource method.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum