This code close access and display this message

  • Thread starter Thread starter 1aae
  • Start date Start date
1

1aae

This code close access and display this message

Microsoft Access has encountered a problem and needs to close. We are sorry
for the inconvenience ..etc
How to edit this code to work correct…

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Here
Select Case HidenFrame
Case 1
Me.RecordSource = "Qry1"
Me.cboGroup.RowSource = "QryCL"
Case 2
Me.RecordSource = "Qry2"
Me.cboGroup.RowSource = "QryDL"

Case 3
Me.RecordSource = "Qry3"
Me.cboGroup.RowSource = "QryEL"

Case 4
Me.RecordSource = "Qry4"
Me.cboGroup.RowSource = "QryFL"
End Select
If (Me.RecordsetClone.RecordCount) = 0 Then
Cancel = True
End If
Here:
Exit sub
Resume
End sub
 
1aae said:
This code close access and display this message

Microsoft Access has encountered a problem and needs to close. We are
sorry for the inconvenience ..etc
How to edit this code to work correct.

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Here
Select Case HidenFrame
Case 1
Me.RecordSource = "Qry1"
Me.cboGroup.RowSource = "QryCL"
Case 2
Me.RecordSource = "Qry2"
Me.cboGroup.RowSource = "QryDL"

Case 3
Me.RecordSource = "Qry3"
Me.cboGroup.RowSource = "QryEL"

Case 4
Me.RecordSource = "Qry4"
Me.cboGroup.RowSource = "QryFL"
End Select
If (Me.RecordsetClone.RecordCount) = 0 Then
Cancel = True
End If
Here:
Exit sub
Resume
End sub

I'm not sure what's wrong. A simple test in which I change the
recordsource of a form in the Open event, then test to
RecordsetClone.RecordCount to cancel the open if it is empty, works fine
for me. Have you verified that each of those queries can be opened
without causing an error? Note that the queries must not refer to
controls on the form, because the form isn't open yet.

What is "HidenFrame"? Not, I hope, a control on the form.

BTW, your error-handling isn't set up correctly, though I don't think
that's the source of your problem. It should be more like this:

Private Sub Form_Open(Cancel As Integer)

On Error GoTo Here

' ... code for routine ...

Proc_Exit:
Exit Sub

Here:
' ... display error message or something? ...
Resume Proc_Exit

End Sub
 
Back
Top