Seacr Form Not Working

Jkittle

Registered User.
Local time
Yesterday, 20:04
Joined
Sep 25, 2007
Messages
100
I've tried modifying some code I found here to make a search form but it’s not working properly. I can't seem to get it right. Can someone look at the code and see what I'm missing?

Private Sub Form_Load()
On Error GoTo Err_Form_Load

Me.Label55.Caption = "ID" & Me.lblDn.Caption

Exit_Form_Load:
Exit Sub

Err_Form_Load:
MsgBox Err.Description, , " GV Health"
Resume Exit_Form_Load

End Sub

Private Sub Label55_Click()
On Error GoTo Err_Label55_Click

If Me.Label55.Caption = "ID" & Me.lblDn.Caption Then
Me.Label55.Caption = "ID" & Me.LblUp.Caption
Me.List0.RowSource = "Q-NCM ID DEC"
Else
Me.Label55.Caption = "ID" & Me.lblDn.Caption
Me.List0.RowSource = "Q-NCM ID ASC"
End If

Me.Label55.BackColor = 8421376
Me.Label56.BackColor = 12615680
Me.Label57.BackColor = 12615680
Me.Label59.BackColor = 12615680

Me.Label56.Caption = " Part Number"
Me.Label57.Caption = " Date"
Me.Label59.Caption = " Router Number"

Me.List0.Requery
Me!List0.Selected(0) = True

Exit_Label55_Click:
Exit Sub

Err_Label55_Click:
MsgBox Err.Description, , " GV Health"
Resume Exit_Label55_Click

End Sub

Private Sub Label56_Click()
On Error GoTo Err_Label56_Click

If Me.Label56.Caption = " Part Number " & Me.lblDn.Caption Then
Me.Label56.Caption = " Part Number " & Me.LblUp.Caption
Me.List0.RowSource = "Q-Part Number DEC"
Else
Me.Label56.Caption = " Part Number " & Me.lblDn.Caption
Me.List0.RowSource = "Q-Part Number ASC"
End If

Me.Label55.BackColor = 12615680
Me.Label56.BackColor = 8421376
Me.Label57.BackColor = 12615680
Me.Label59.BackColor = 12615680

Me.Label55.Caption = "ID"
Me.Label57.Caption = " Date"
Me.Label59.Caption = " Router Number"

Me.List0.Requery
Me!List0.Selected(0) = True

Exit_Label56_Click:
Exit Sub

Err_Label56_Click:
MsgBox Err.Description, , " GV Health"
Resume Exit_Label56_Click

End Sub

Private Sub Label57_Click()
On Error GoTo Err_Label57_Click

If Me.Label57.Caption = " Date " & Me.lblDn.Caption Then
Me.Label57.Caption = " Date " & Me.LblUp.Caption
Me.List0.RowSource = "Q-Date DEC"
Else
Me.Label57.Caption = " Date " & Me.lblDn.Caption
Me.List0.RowSource = "Q-Date ASC"
End If

Me.Label55.BackColor = 12615680
Me.Label56.BackColor = 12615680
Me.Label57.BackColor = 8421376
Me.Label59.BackColor = 12615680

Me.Label55.Caption = " ID"
Me.Label56.Caption = " Part Number"
Me.Label59.Caption = " Router Number"

Me.List0.Requery
Me!List0.Selected(0) = True

Exit_Label57_Click:
Exit Sub

Err_Label57_Click:
MsgBox Err.Description, , " GV Health"
Resume Exit_Label57_Click

End Sub

Private Sub Label59_Click()
On Error GoTo Err_Label59_Click

If Me.Label59.Caption = " Router Number " & Me.lblDn.Caption Then
Me.Label59.Caption = " Router Number " & Me.LblUp.Caption
Me.List0.RowSource = "Q-Router # DEC"
Else
Me.Label59.Caption = " Router Number " & Me.lblDn.Caption
Me.List0.RowSource = "Q-Router # ASC"
End If

Me.Label55.BackColor = 12615680
Me.Label56.BackColor = 12615680
Me.Label57.BackColor = 12615680
Me.Label59.BackColor = 8421376

Me.Label55.Caption = "ID"
Me.Label56.Caption = " Part Number"
Me.Label57.Caption = " Date"

Me.List0.Requery
Me!List0.Selected(0) = True

Exit_Label59_Click:
Exit Sub

Err_Label59_Click:
MsgBox Err.Description, , " GV Health"
Resume Exit_Label59_Click

End Sub

Private Sub List0_DblClick(Cancel As Integer)
On Error GoTo Err_List0_DblClick
Dim rs As Object

DoCmd.OpenForm "NCM New Record"

Set rs = Forms!NCM New Record.Recordset.Clone
rs.FindFirst "ID = " & Me.List0
Forms!NCM New Record.Bookmark = rs.Bookmark

Exit_List0_DblClick:
Exit Sub

Err_List0_DblClick:
MsgBox Err.Description, , " GV Health"
Resume Exit_List0_DblClick

End Sub

Private Sub txtSearch_Change()
Dim vSearchString As String

vSearchString = txtSearch.Text
txtSearch2.Value = vSearchString
Me.List0.Requery

End Sub

vSearchString = txtSearch.Text
txtSearch2.Value = vSearchString
Me.List0.Requery

End Sub
 

Attachments

It might help us if we knew what it is you want to do and what the code is doing now..

Does anything come up?

Can you narrow down where the problem is in the code?

You have so many SUB's in the code it is hard to tell what you are doing where.

Or you could check out the Samples on this site. You will find many examples of search methods.
 
What I'm trying to do is have a search form "F-NCM Search" open up with a list box containing the information the users need to do a search. I wanted to be able to have the record move up and down in ascending and descending order on clicks (partially works) or be able to type in the search text box and have the records start to show up if any part of the text matches a record (does not work). If a records match is found a double click on that line would open up the "NCM New Record" form to that record.

On line 178 when I use the text box to type in a get an error. I have seached this site and this search idea came from someone here but I can't get it to work properly.
 
JK,

Your query [Q-NCM Search] needs to use txtSearch2 as the Criteria for the
ID field.

And your "End Sub" in the middle of the OnChange Event should be an
Exit Sub and lose the duplicate code after it.

Wayne
 
Search Form

Wayne,

When I use the tatsearch2 in the NCM query nothing shows up in the list box and I don't see what your talking about in the code.

If I type in the text box I get a complie error an this is where the code open up to (See attachement):

Private Sub txtSearch_Change()
Dim vSearchString As String

vSearchString = txtSearch.Text
txtSearch2.Value = vSearchString
Me.List0.Requery

End Sub

vSearchString = txtSearch.Text
txtSearch2.Value = vSearchString
Me.List0.Requery

End Sub
 

Attachments

JK,

Delete the Bold code:

Code:
Private Sub txtSearch_Change()
Dim vSearchString As String

vSearchString = txtSearch.Text
txtSearch2.Value = vSearchString
Me.List0.Requery

End Sub

[B]vSearchString = txtSearch.Text
txtSearch2.Value = vSearchString
Me.List0.Requery

End Sub[/B]

The Criteria for the ID field is not --> txtSearch2

It is --> Forms![F-NCM Search]![txtSearch2]



Wayne
 
Wayne,

Okay the search field is now working (thanks). But please bear with me as I'm new to VB. I do still not understand what I need to do with the txtsearch2. And when I double clicked on a row in the list box it was supposed to take me to that record in the "New NCm Record" and I get a syntax error at:

Private Sub List0_DblClick(Cancel As Integer)
On Error GoTo Err_List0_DblClick
Dim rs As Object

DoCmd.OpenForm "NCM New Record"

Set rs = Forms!NCM New Record.Recordset.Clone
rs.FindFirst "ID = " & Me.List0
Forms!NCM New Record.Bookmark = rs.Bookmark

Exit_List0_DblClick:
Exit Sub

Err_List0_DblClick:
MsgBox Err.Description, , " GV Health"
Resume Exit_List0_DblClick

End Sub
 
JK,

For starters:

Set rs = Forms!NCM New Record.Recordset.Clone

When you have spaces in object names (bad idea), use square brackets:

Set rs = Forms![NCM New Record].Recordset.Clone

If that doesn't fix it, I'll have to look later.

Wayne
 
Search Fixed

Wayne,

It works perfect! The brackets were all I needed, thank you so much for your help.

Jerry.
 

Users who are viewing this thread

Back
Top Bottom