Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code for Record Not Found 1

Status
Not open for further replies.

kentwoodjean

Technical User
Oct 19, 2002
376
0
0
US
I am looking for some help on writing a code. I have a form that is made based on a membership query. Upon entering a contract number in the first field, all other fields pertenent to the customer will populate (addr, city, state etc will appear. To accomplish this I am using an 'unbound' text box with the following code:

Private Sub ContractNum_AfterUpdate()
Dim szSQL As String

szSQL = "select * from qryMembership where Contract_Num = """ & Trim(Me.ContractNum) & """;"

Me.RecordSource = szSQL
End Sub


What I would like to do is have some type of error message that will aappear saying "Record not Found. I am learning Visual Basic and really don't now how to do this. Any help is appreciated. I checked the posts and couldn't find one for Access. thanks.
 


Hi, Tics not quotes...
Code:
    szSQL = "select * from qryMembership where Contract_Num = '" & Trim(Me.ContractNum) & "';"


Skip,
[sub]
[glasses] [red]Be Advised![/red] A man who jumps from a bridge in Paris, is…
INSANE! [tongue][/sub]
 
Thanks for the response. I changed my szSQL statement as yours and puposely put in an incorrect contract number but did not get a message to say I had to wrong number or it was not found. Can a message of this type be built into this?
 


A criteria that returns no data is NOT an error.

However you can wite code that would advide the user that the recordset is empty.

Skip,
[sub]
[glasses] [red]Be Advised![/red] A man who jumps from a bridge in Paris, is…
INSANE! [tongue][/sub]
 
That is exactly what I am looking for but apparently didn't know how to phase my question. I am at somewhat of a loss as to how to do this.
 


Well you have a recordset object. If the EOF and BOF properties are both TRUE after you use the MoveFirst method, then you have no rows returned.

Skip,
[sub]
[glasses] [red]Be Advised![/red] A man who jumps from a bridge in Paris, is…
INSANE! [tongue][/sub]
 
I had to look up EOF and BOF defnitions to understand these properties. What I am curious about is the "on open" property for the form. It shows:

Private Sub ContractNum_Enter()
Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "No matches. Try again."
Cancel = True
End If
End Sub

This would tell me that if there are no records then a msgBox should appear with the above message. Is that correct?

This form is used to provide additional data on an ongoing basis based on several thousand members loaded in the membership file. If when I put in a contract number that does not exist, why does the above message not show up in a message box? Or does this message have to be alined with the unbound text box?






 


You're probably going to be better off in one of the Access forums is this is an Access form.

Skip,
[sub]
[glasses] [red]Be Advised![/red] A man who jumps from a bridge in Paris, is…
INSANE! [tongue][/sub]
 
thanks, and I have now posted in the "Forms" forum in hopes to understand how to get the result that I am looking for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top