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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OpenForm with a filter results in no records

Status
Not open for further replies.

beec

Programmer
Apr 3, 2002
13
0
0
GB
Hello,

I use a second form to add extra data to a record. Both records are linked by an ID.
Here's my problem :
When I want to open the second form, i do it with this code line :
DoCmd.OpenForm "frmVerschildrukmeters", acNormal, "", "[LokatieID]=[Forms]![frmInstallaties]![ID]", , acNormal
This results normaly in opening the corresponding record in the second form. So far so good, but when there is not yet a record corresponding in the second form, I get an error because there is nothing on the open form (because of the filter).
Is there a way to detect that there is no result from the filter ?
When there is no corresponding record, I want to create one with the correct ID automaticly filled in.

TNX in advance.
B.
 
Hi,

there are a couple of ways to do this, but I guess the cleanest way would be to just trap the error (do you get an error message and if so what is it?) or check the recordcount OnOpen if there is no error message.

Let me know if there's a message and if so what the error number is and I'll write the trapping code for you or if there is no message then the recordcount check would look like this:

Private Sub Form_Open()

If Me.RecordselClone.Recordcount = 0 Then
Me.FilterOn = False
DoCmd.GotoRecord , , acNewRecord
Me!txtLokatieID=[Forms]![frmInstallaties]![ID]
End If

Exit Sub Kyle [pc2]
 
TNX Kyle,

It works. I still had to change some small things in your syntax : RecordsetClone in stead of RecordselClone
acNewRec in stead of acNewRecord
but those things were easy to fix.
With this few lines I could even trow away a lot of other code I wrote to close the form and then reopen it to add a new record etc.

Great tip ! Thanks again !

B.
 
Happy to help!

Sorry about the typo's I was writing it freehand... Kyle [pc2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top