This code close access and display this message

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
 
D

Dirk Goldgar

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
 

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