Hi All
I'm still learning so please accept my apologies for what is probably a beginner's mistake.
I have made a form with a subform to search for existing records based on inputting a postcode then selecting the relevant address from the subform which then fills the form with details of that chosen record ready to issue a further package linked to that original record.
To prevent errors and confusion by the users I coded the following:
Private Sub CmdFindAddress_Click()
If IsNull(Me.TxtPostcode) Then
MsgBox "You need a Postcode to use this button. Please type one in."
Me.TxtPostcode.SetFocus
Exit Sub
End If
If Len(Me.TxtPostcode) <> 8 Then
MsgBox "The postcode should be 8 characters long. Please type it in again."
Me.TxtPostcode.SetFocus
Exit Sub
End If
If DCount("Property_id", "dbo_Property", "[Postcode] = Forms!frmRetestSearch.TxtPostcode") = 0 Then
MsgBox "Error - there are no records with the postcode you have entered. Please check it and type it in again."
Me.TxtPostcode.SetFocus
Exit Sub
End If
Me.TxtPostcode = UCase(Me.TxtPostcode)
Me.NumOrigCrn = Null
'Where the postcode entered does not exist in records or if there is a mistake typing in the postcode, below will remove residual record details from previous postcode ready for a new postcode search:
For Each ctlCurr In Me.Controls
If ctlCurr.Tag = "clear" Then
ctlCurr = Null
End If
Next ctlCurr
Me.Refresh
End Sub
.........
The problem is that if I test the system by inputting a postcode where I know there are no records, the CtlCurr is highlighted and the error message is:
Compile error: variable not defined
..........
This does not happen if I have already selected a postcode so the record fields are filled and then change the postcode - so the record fields are cleared.
Previously, entering a postcode which did not match existing records generated the "there are no records...." error message instead.
Would you please advise - how do I define CtlCurr?
Thank you !
KateM
I'm still learning so please accept my apologies for what is probably a beginner's mistake.
I have made a form with a subform to search for existing records based on inputting a postcode then selecting the relevant address from the subform which then fills the form with details of that chosen record ready to issue a further package linked to that original record.
To prevent errors and confusion by the users I coded the following:
Private Sub CmdFindAddress_Click()
If IsNull(Me.TxtPostcode) Then
MsgBox "You need a Postcode to use this button. Please type one in."
Me.TxtPostcode.SetFocus
Exit Sub
End If
If Len(Me.TxtPostcode) <> 8 Then
MsgBox "The postcode should be 8 characters long. Please type it in again."
Me.TxtPostcode.SetFocus
Exit Sub
End If
If DCount("Property_id", "dbo_Property", "[Postcode] = Forms!frmRetestSearch.TxtPostcode") = 0 Then
MsgBox "Error - there are no records with the postcode you have entered. Please check it and type it in again."
Me.TxtPostcode.SetFocus
Exit Sub
End If
Me.TxtPostcode = UCase(Me.TxtPostcode)
Me.NumOrigCrn = Null
'Where the postcode entered does not exist in records or if there is a mistake typing in the postcode, below will remove residual record details from previous postcode ready for a new postcode search:
For Each ctlCurr In Me.Controls
If ctlCurr.Tag = "clear" Then
ctlCurr = Null
End If
Next ctlCurr
Me.Refresh
End Sub
.........
The problem is that if I test the system by inputting a postcode where I know there are no records, the CtlCurr is highlighted and the error message is:
Compile error: variable not defined
..........
This does not happen if I have already selected a postcode so the record fields are filled and then change the postcode - so the record fields are cleared.
Previously, entering a postcode which did not match existing records generated the "there are no records...." error message instead.
Would you please advise - how do I define CtlCurr?
Thank you !
KateM