Hi guys. I made a unbounded form that has option to search for customerno .
Whenever I try type a customerno and click on the search button I get the following error.
I be happy if some expert help fix this error. Thanks
Error
Run -time error '2109':
There is no field named 'customerno' in the current record
http://i5.photobucket.com/albums/y18...earcherror.jpg
=====>searcherror pic of the form
Code:
Option Compare Database
Option Explicit
Sub clearTextBoxes()
''clearing the tow texboxes txtCompanyName and txtCustomerId
Me.customerNumber.Value = ""
Me.customerName.Value = ""
End Sub
Sub getReadyForAnAddOperation()
Me.cmdSave__.Enabled = True
Me.cmdSave__.SetFocus
Me.cmdCancel.Enabled = True
Me.cmdAdd__.Enabled = False
Me.cmdEdit.Enabled = False
Me.cmdDelete.Enabled = False
End Sub
Sub stateOnLoad()
Me.customerName.SetFocus
Me.cmdCancel.Enabled = True
Me.cmdSave__.Enabled = False
Me.cmdEdit.Enabled = True
Me.cmdAdd__.Enabled = True
'''disableing the cancel and save button on load
'''Me.cmdCancel.Enabled = False
'''Me.cmdSave__.Enabled = False
End Sub
'declaring subrotine
Sub FillFeilds()
Me.customerNumber = myRS.Fields("customerno")
Me.customerName = myRS.Fields("customername")
End Sub
Private Sub cmdAdd___Click()
clearTextBoxes
getReadyForAnAddOperation
pbAddingARecord = True
'''changing the value of this boolean variable
myRS.AddNew
End Sub
Private Sub cmdCancel_Click()
FillFeilds
stateOnLoad
End Sub
Private Sub cmdDelete_Click()
Dim x As Variant
x = MsgBox(" You are abut to delete " & Me.customerName & " from this table - proceed ? ", vbOKCancel)
If x = 1 Then
With myRS
.Delete
.MoveFirst
FillFeilds
stateOnLoad
End With
End If
End Sub
Private Sub cmdEdit_Click()
''clearTextBoxes
getReadyForAnAddOperation
pbEditingARecord = True
'''changing the value of this boolean variable
End Sub
Private Sub cmdMoveFirst_Click()
myRS.MoveFirst
FillFeilds
End Sub
Private Sub cmdMoveLast_Click()
myRS.MoveLast
FillFeilds
End Sub
Private Sub cmdMoveNext_Click()
If pbAddingARecord = True Or pbEditingARecord = True Then
MsgBox ("Please save or cancel changes first ")
Exit Sub
End If
myRS.MoveNext
If myRS.EOF Then
MsgBox ("Last Record")
myRS.MovePrevious
End If
FillFeilds
End Sub
Private Sub cmdMovePreviouse_Click()
myRS.MovePrevious
If myRS.BOF Then
MsgBox (" First record")
myRS.MoveNext
End If
FillFeilds
End Sub
Private Sub cmdSave___Click()
If pbAddingARecord = True Then
myRS.AddNew
End If
If pbEditingARecord = True Then
myRS.Edit
End If
'''inserting the value of textboxes to the table fields.feeding the date to record set
myRS.Fields("customerno").Value = Me.customerNumber.Value
myRS.Fields("customername").Value = Me.customerName.Value
'''calling update method. it comittes the changes
myRS.Update
pbAddingARecord = False
pbEditingARecord = False
stateOnLoad
End Sub
Private Sub cmdSearch_Click()
Dim strStudentRef 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 customerno
DoCmd.ShowAllRecords
DoCmd.GoToControl ("customerno")
DoCmd.FindRecord Me!txtSearch
'''Me.customerno.SetFocus
customerNumber.SetFocus
strStudentRef = customerNumber.Text
txtSearch.SetFocus
strSearch = txtSearch.Text
'If matching record found sets focus in customerNumber and shows msgbox
'and clears search control
If strStudentRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
customerNumber.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 Form_Load()
Set db = CurrentDb()
'''Set myRS = db.OpenRecordset("select * from customer")
Set myRS = db.OpenRecordset("customer", dbOpenTable)
''' need to learn how to add index to customer table
'''myRS.Index = ("Company Name")
'calling subroutine
stateOnLoad
FillFeilds
End Sub
Private Sub lblFindIt_Click()
With myRS
Select Case Me.lblFindIt.Caption
Case "Company Name"
Me.lblFindIt.Caption = " First Name "
''' this indexcontactfirstname should already exist in the table
''' you can also create index trough code on tables. this method
''' not good in multi user evironment . best way to create indexes and
''' refere them trough code
.Index = "CotactFirstName"
Case "First Name"
Me.lblFindIt.Caption = " Last Name "
.Index = "CotactLastName"
Case "Last Name "
Me.lblFindIt.Caption = "Company Name "
.Index = "CompanyName"
End Select
End With
End
End Sub
Private Sub textFindIt_Change()
Dim strSeek As Variant
Dim posInmyRS As Variant
''' feeding it the value from text box
strSeek = Me![textFindIt].Text
With myRS
posInmyRS = myRS.Bookmark
.Seek ">=", strSeek
If .NoMatch = True Then
myRS.Bookmark = posInmyRS
Exit Sub
End If
FillFeilds
End With
End Sub