I am trying to use a cmdSearch command button. I have a query that I built
the form page from and I need the ability to type in a part number and have
the cmdSearch find the record. The query is named PARTSEARCH and the part
field is 2nditemnum as MODEL. Please take a look and let me know why this
won’t run. I can give more detail.
Option Compare Database
Private Sub cmdSearch_Click()
Dim strPARTSEARCHRef As String
Dim strSearch As String
'Check txtSearch for Null value or Nill Entry first.
If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criteria!"
Me![txtSearch].SetFocus
Exit Sub
End If
'---------------------------------------------------------------
'Performs the search using value entered into txtSearch
DoCmd.ShowAllRecords
DoCmd.GoToControl ("2NDITEMNUM AS MODEL")
DoCmd.FindRecord Me!txtSearch
str2NDITEMNUM AS MODEL.SetFocus
strPARTSEARCHRef = str2NDITEMNUM AS MODEL.Text
txtSearch.SetFocus
strSearch = txtSearch.Text
'If matching record found sets focus in and shows msgbox
'and clears search control
If strSEARCHRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
str2NDITEMNUM As MODEL.SetFocus
txtSearch = ""
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try
Again.", _
, "Invalid Search Criterion!"
txtSearch.SetFocus
End If
End Sub
Private Sub txtSearch_BeforeUpdate(Cancel As Integer)
End Sub
> Don't use DLookup for that,
>
[quoted text clipped - 9 lines]
> > form page that the project managers can type in a part number and retrieve
> > all the specs of the part. Can I use the dlookup to do this?
Ofer Cohen - 07 May 2007 18:10 GMT
What error do you get?
Also, when you have a name of a control , field, table that consist more the
one word it need to be in square brackets
DoCmd.GoToControl ("[2NDITEMNUM AS MODEL]")
Is that "[2NDITEMNUM AS MODEL]" the text box name?
Note: It's not recomnded to give names to the controls when they consist
more then one word.
You can write it as, so it will be connected
2NDITEMNUM_AS_MODEL

Signature
Good Luck
BS"D
> I am trying to use a cmdSearch command button. I have a query that I built
> the form page from and I need the ability to type in a part number and have
[quoted text clipped - 66 lines]
> > > form page that the project managers can type in a part number and retrieve
> > > all the specs of the part. Can I use the dlookup to do this?
tmaxwell - 07 May 2007 18:31 GMT
The error is "There is no field named 2NDITEMNUM AS MODEL in the current
record"
[Daily Sales].[2NDITEMNUM] AS MODEL so I have named it 2NDITEMNUM as MODEL
> What error do you get?
>
[quoted text clipped - 81 lines]
> > > > form page that the project managers can type in a part number and retrieve
> > > > all the specs of the part. Can I use the dlookup to do this?
Ofer Cohen - 07 May 2007 18:46 GMT
If the field name MODEL then try
DoCmd.GoToControl ("MODEL")

Signature
Good Luck
BS"D
> The error is "There is no field named 2NDITEMNUM AS MODEL in the current
> record"
[quoted text clipped - 86 lines]
> > > > > form page that the project managers can type in a part number and retrieve
> > > > > all the specs of the part. Can I use the dlookup to do this?
tmaxwell - 08 May 2007 21:31 GMT
It works right through the DoCmd.GoToControl ("MODEL") but hangs at the
DoCmd.FindRecord Me!txtSearch . Do I need to add the FindFirst option?
Private Sub cmdsearch_Click()
Dim strPARTSRef As String
Dim strSearch As String
If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtSearch].SetFocus
Exit Sub
End If
'---------------------------------------------------------------
DoCmd.ShowAllRecords
DoCmd.GoToControl ("MODEL")
DoCmd.FindRecord Me!txtSearch
strMODEL.SetFocus
strPARTSRef = strMODEL.Text
txtSearch.SetFocus
strSearch = txtSearch.Text
If strPARTSRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congrats!"
strMODEL.SetFocus
txtSearch = ""
Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try
Again.", _
, "Invalid Search Criterion!"
txtSearch.SetFocus
End If
End Sub
> If the field name MODEL then try
>
[quoted text clipped - 90 lines]
> > > > > > form page that the project managers can type in a part number and retrieve
> > > > > > all the specs of the part. Can I use the dlookup to do this?
Ofer Cohen - 08 May 2007 23:21 GMT
Can you post your mdb to
chamudim <@> hotmail <.> com
I'll would like to have a look at it.
If you don't mind sending it, then zip it first because hotmail has issues
with mdb's

Signature
Good Luck
BS"D
> It works right through the DoCmd.GoToControl ("MODEL") but hangs at the
> DoCmd.FindRecord Me!txtSearch . Do I need to add the FindFirst option?
[quoted text clipped - 130 lines]
> > > > > > > form page that the project managers can type in a part number and retrieve
> > > > > > > all the specs of the part. Can I use the dlookup to do this?