My filter is going crazy if there's recordsettype on it

M

Marco

Hello.

I'm using this code to open a form with a filter/criteria:
DoCmd.OpenForm "41_form_Cria_Planos_Expedicao", , , "Id = " &
Me.[43_form_Visualiza_PlanosExpedicao subform].Form.ID

and then on the form I have a code that checks if the record is closed or
not in order to block all that and preventing to be edited or deleted:
If Me.FechadoQA = True Then
Me.RecordsetType = 2
Else
Me.RecordsetType = 0
End If

What is happening is that when I put the code to check if is closed or not
the filter don't work because the form opens with the first record, like
there was no filter before.

What I'm I doing wrong?

Regards,
Marco
 
M

Marshall Barton

Marco said:
I'm using this code to open a form with a filter/criteria:
DoCmd.OpenForm "41_form_Cria_Planos_Expedicao", , , "Id = " &
Me.[43_form_Visualiza_PlanosExpedicao subform].Form.ID

and then on the form I have a code that checks if the record is closed or
not in order to block all that and preventing to be edited or deleted:
If Me.FechadoQA = True Then
Me.RecordsetType = 2
Else
Me.RecordsetType = 0
End If

What is happening is that when I put the code to check if is closed or not
the filter don't work because the form opens with the first record, like
there was no filter before.


I have never tried to do things that way, so I don't know
for surem but I think you might have to reapply the filter.

The way I usually deal with your kind of situation is to set
the form's AllowEdits and AllowDeletions properties.

The issue with using those properties is that it also
prevents use of unbound controls for such things as
searching. In this case, I set the Tag property of the
bounf controls to something like LOCK. Then those controls
can be locked/unlocked using a procedure like this air code:

Private Sub SetLocks(OnOff As Boolean)
Dim ctl As Control
For Each ctl in Me.Controls
If ctl.Tag = "LOCK" Then ctl.Locked = OnOff
Next ctl
End Sub
 
M

Marco

Hi.

I'm sorry i didn't catch. What do I do with that code?

Do I put it on form?

Please don't give up on me. :)

Regards,
Marco




Marshall Barton said:
Marco said:
I'm using this code to open a form with a filter/criteria:
DoCmd.OpenForm "41_form_Cria_Planos_Expedicao", , , "Id = " &
Me.[43_form_Visualiza_PlanosExpedicao subform].Form.ID

and then on the form I have a code that checks if the record is closed or
not in order to block all that and preventing to be edited or deleted:
If Me.FechadoQA = True Then
Me.RecordsetType = 2
Else
Me.RecordsetType = 0
End If

What is happening is that when I put the code to check if is closed or not
the filter don't work because the form opens with the first record, like
there was no filter before.


I have never tried to do things that way, so I don't know
for surem but I think you might have to reapply the filter.

The way I usually deal with your kind of situation is to set
the form's AllowEdits and AllowDeletions properties.

The issue with using those properties is that it also
prevents use of unbound controls for such things as
searching. In this case, I set the Tag property of the
bounf controls to something like LOCK. Then those controls
can be locked/unlocked using a procedure like this air code:

Private Sub SetLocks(OnOff As Boolean)
Dim ctl As Control
For Each ctl in Me.Controls
If ctl.Tag = "LOCK" Then ctl.Locked = OnOff
Next ctl
End Sub
 
M

Marshall Barton

The code I posted would go in the form's module.

Then you would also add a line of code the form's Current
event procedure:
SetLocks Nz(Me.FechadoQA, False)
--
Marsh
MVP [MS Access]

I'm sorry i didn't catch. What do I do with that code?

Do I put it on form?


Marshall Barton said:
Marco said:
I'm using this code to open a form with a filter/criteria:
DoCmd.OpenForm "41_form_Cria_Planos_Expedicao", , , "Id = " &
Me.[43_form_Visualiza_PlanosExpedicao subform].Form.ID

and then on the form I have a code that checks if the record is closed or
not in order to block all that and preventing to be edited or deleted:
If Me.FechadoQA = True Then
Me.RecordsetType = 2
Else
Me.RecordsetType = 0
End If

What is happening is that when I put the code to check if is closed or not
the filter don't work because the form opens with the first record, like
there was no filter before.


I have never tried to do things that way, so I don't know
for surem but I think you might have to reapply the filter.

The way I usually deal with your kind of situation is to set
the form's AllowEdits and AllowDeletions properties.

The issue with using those properties is that it also
prevents use of unbound controls for such things as
searching. In this case, I set the Tag property of the
bounf controls to something like LOCK. Then those controls
can be locked/unlocked using a procedure like this air code:

Private Sub SetLocks(OnOff As Boolean)
Dim ctl As Control
For Each ctl in Me.Controls
If ctl.Tag = "LOCK" Then ctl.Locked = OnOff
Next ctl
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