DoCmd.GoToControl "[MODEL]"

T

toddjmaxwell

This hangs on the DoCmd.GoToControl "MODEL" with MODEL being the field
in the query. Query name PARTSEARCH and the form page is named
PARTSSEARCH (extra S in the form page name)

The errors is, There is no field named "MODEL" in current record



Private Sub cmdsearch_Click()
Dim strPARTSEARCHRef As String
Dim strSearch As String



If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
MsgBox "Please enter Part Number!", vbOKOnly, "Invalid Search
Criteria!"
Me![txtSearch].SetFocus
Exit Sub

End If


DoCmd.ShowAllRecords
DoCmd.GoToControl "[MODEL]"
DoCmd.FindRecord Me![txtSearch]

strpartSearch.SetFocus
strPARTSEARCHRef = strMODEL.Text
txtSearch.SetFocus
strSearch = txtSearch.Text


If strSEARCHRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
strMODEL.SetFocus
txtSearch = ""


Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _
, "Invalid Search Criterion!"
txtSearch.SetFocus
End If

End Sub
 
B

BruceM

See inline.

This hangs on the DoCmd.GoToControl "MODEL" with MODEL being the field
in the query. Query name PARTSEARCH and the form page is named
PARTSSEARCH (extra S in the form page name)

The errors is, There is no field named "MODEL" in current record



Private Sub cmdsearch_Click()
Dim strPARTSEARCHRef As String
Dim strSearch As String



If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then

Simplified version of this first line:
If Nz(Me.txtSearch) = "" Then
MsgBox "Please enter Part Number!", vbOKOnly, "Invalid Search
Criteria!"
Me![txtSearch].SetFocus
Exit Sub

End If


DoCmd.ShowAllRecords
DoCmd.GoToControl "[MODEL]"

A control is a text box, combo box, label, or just about anything else on a
form or report. It is, however, not the field itself. The field and the
control to which it is bound should have different names (Model and
txtModel, for instance). You need to reference the Control, not the Field.
DoCmd.FindRecord Me![txtSearch]

strpartSearch.SetFocus

What is strPartSearch? If it is a string, you can't set the focus to it.
strPARTSEARCHRef = strMODEL.Text

The Text property only works when a control has the focus. strPartSearch
has the focus, according to the previous line (assuming it is a control that
can accept the focus), so the Text property of strMODEL (what is strMODEL?)
isn't available. If you want to set strPartSearchRef to the value of a
control, just use the control name: Me.txtMODEL
txtSearch.SetFocus

You don't need that line. Just modify the following line to strSearch =
Me.txtSearch
strSearch = txtSearch.Text


If strSEARCHRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
strMODEL.SetFocus

Why are you setting the focus?
txtSearch = ""


Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _
, "Invalid Search Criterion!"
txtSearch.SetFocus
End If

End Sub

This is hard to follow. For one thing, there is no way of knowing what the
various names of controls or strings or whatever mean. It sounds as if you
are searching for a particular part number. If so, why not use a combo box
that gets its list from the part numbers that are already in the system?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

DoCmd.FindRecord Me! 6
Record Search within a Form 3
cmdSearch_Click 1
Invalid Qualifier 0
Seaching using text box 6
Access Form Validation 2
Enter new record if search returns no results? 17
Search Button 2

Top