popup issue if no existing record

D

deb

On the form f001ProjectReview I have a button with the below code.
It works great if the form fClosureApprovalPopUp has an existing record. If
there is no record to match the ProjectID key then I get error 3048, cannot
open anymore databases.

Private Sub btnReqClose_Click()
On Error GoTo Err_btnReqClose_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "fClosureApprovalPopUp"

stLinkCriteria = "[ProjectID]=" & Me![ProjectID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_btnReqClose_Click:
Exit Sub

Err_btnReqClose_Click:
MsgBox Err.Description
Resume Exit_btnReqClose_Click

End Sub


it highlights the code...
If Me.[fClosureApproval].Form.RecordsetClone.RecordCount = 0 Then
in the below
Private Sub Form_Current()

If Me.[fClosureApproval].Form.RecordsetClone.RecordCount = 0 Then
Me.btnReqClose.Visible = True
Else
Me.btnReqClose.Visible = False
End If

Your help is badly needed!!
 
J

Jeanette Cunningham

You can test for any records matching the ProjectID before you open the
popup.
If the popup wouldn't have any records, don't open it.
If you don't open the popup, that error won't occur.

Use a saved query to do the check for matching records.
The query would be based on the record source for the popup.

Dim lngCount as Long
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "fClosureApprovalPopUp"
stLinkCriteria = "[ProjectID]=" & Me![ProjectID]

lngCount = DCount("*", "TheSavedQuery", stLinkCriteria)
If lngCount >0 Then
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

Note: replace TheSavedQuery with the name of the query.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top