run-time error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to perform a search for a record based on a text box value in a
sub-form. I keep getting run-tim error 2109. Can't get it to work. Any ideas?
Thank you?

The debugger says I have a problem with "DoCmd.GoToControl ("pkglotnumber")"
I have checked it and it seems to be correct.
 
You need to set the focus first to the sub form

Me.[SubFormControlName].SetFocus
DoCmd.GoToControl ("pkglotnumber")
 
I Tried putting the Me.[SubFormControlName].setfocus right before the
DoCmd.GoToControl ("pkglotnumber") just how you had it and can't get it to
work. The form name is "packagingsubform" Here is the code and how I had
it...

Private Sub cmdsearch_Click()

Dim pkglotnumberRef 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 Criterion!"
Me![txtSearch].SetFocus
Exit Sub
End If
'---------------------------------------------------------------

'Performs the search using value entered into txtSearch
'and evaluates this against values in pkglotnumber

DoCmd.ShowAllRecords
Me.[packagingsubform].setfocus
DoCmd.GoToControl ("pkglotnumber")
DoCmd.FindRecord Me!txtSearch

pkglotnumber.SetFocus
pkglotnumberRef = pkglotnumber.Text
txtSearch.SetFocus
strsearch = txtSearch.Text

'If matching record found sets focus in pkglotnumber and shows msgbox
'and clears search control

If pkglotnumberRef = strsearch Then
MsgBox "Match Found For: " & strsearch, , "Congratulations!"
pkglotnumber.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

I also need to put the search on the main form as well. Can that be done?

Thanks
Marc

Ofer Cohen said:
You need to set the focus first to the sub form

Me.[SubFormControlName].SetFocus
DoCmd.GoToControl ("pkglotnumber")

--
Good Luck
BS"D


Marc said:
I am trying to perform a search for a record based on a text box value in a
sub-form. I keep getting run-tim error 2109. Can't get it to work. Any ideas?
Thank you?

The debugger says I have a problem with "DoCmd.GoToControl ("pkglotnumber")"
I have checked it and it seems to be correct.
 
Back
Top