First off, I want to apologize for my last couple of posts. I know that everyone is doing their best to help me and I haven't been clear it what I have been trying to accomplish with this database. I really should have walked away from the problems for a bit and come back to it with fresh eyes, I am sorry for being rude.
Secondly,
As I thought about the problem over the weekend I managed to come up with a solution this morning. After some trial and error with some new queries and forms I came up with code for the search button on my wireCategory_v3 form
Code:
Private Sub searchBtn_Click()Dim strSearch As String
'Dim qryComp As Integer
strSearch = Me.formSearch
qryComp = StrComp([Forms]![wireCategoryQuery_v3]![formSearch], [strSearch], [vbBinaryCompare])
If [qryComp] = 0 Then
' DoCmd.OpenQuery "qryWireNumber", [acViewNormal], acEdit
' DoCmd.OpenForm "frmQryWireNumber", [acNormal], , WhereCondition:="wireNumber='" & formSearch & "'"
' DoCmd.OpenForm "wireCategoryQuery_v3", acNormal, , WhereCondition:="wireNumber='" & frmSearchWireNumberTxtBox & "'"\
DoCmd.OpenForm "wireCategoryQuery_v3", acNormal, , WhereCondition:="wireNumber='" & formSearch & "'"
Else
End If
End Sub
While the code does work I am guessing that I over complicated the code and better solutions have been provided.
@Welshgasman
Another option as you are already on the form is just find the record, not filter, then you do not need to switch the filter off all the time.
Code:
Private Sub searchBtn_Click()
Dim strSearch As String
strSearch = Me.formSearch
'DoCmd.OpenForm "wireCategoryQuery_V3", , , WhereCondition:="wireNumber='" & strSearch & "'"
With Me.Recordset
.FindFirst "wireNumber='" & strSearch & "'"
End With
End Sub
Try it in your DB. Make sure Data Entry is No though.
I tried the code and it works great. I like not having to switch the filter on and off all the time.
Can you help walk me through the code?
Code:
strSearch = Me.formSearch
takes what was typed into the formSearch text box
Code:
With Me.Recordset
.FindFirst "wireNumber='" & strSearch & "'"
I am guessing that Me.Record set is the control telling access to look at all the records in the wireCatergoryQuery becasue the wireCategoryQuery_V3 form is based off that query.
Then everything after FindFirst is saying "hey, grab the first record that matches the variable strSearch".
Is that correct?
My only concern is having Data Entry set to NO. We have another access database for tracking equipment maintenance and we have ran it issues where we've tried to add equipment and over written a record because a record was open on the screen. So I was trying to avoid that by setting the form Data Entry to NO, but I am guess that a combination of checking what information is being entered against information already in the database and opening the form to a new record would address that issue. Would it be a good Idea to index my wireInfo table by wireNumber and not allow duplicates?
BTW, your Update button appears to create a new record?, so perhaps change the Caption to Add ?
The update button was my attempt at having a way to update an existing record, but I just used the macro wizard and created a glorified create new button. I think I need to look at the list Do.Cmd and look for something to simply update a record.
@orange
I like the idea of a drop down menus for existing the existing wire numbers, but with thousands of wire I think I would have to find a way to filter by category first. But I will give it a shot.
In the interest for getting away from using macros, I am going to try and redo my Save, Update and Delete buttons with VBA code.
Since this thread is about getting the search function working, I am betting it would be better to start a new thread for those if and when I need help on writing the code for those buttons, Correct?