Access 2003 to 2007 Code not working

pgsibson

Registered User.
Local time
Today, 17:41
Joined
Jan 24, 2008
Messages
44
Hi Everyone
I have a form that displays the results of a query. I have a combo box to select and filter information on this form. All worked well in 2003 but 2007 goes awry. Initially I have 957 results displayed from the query and after the initial selection from the combo code is

Private Sub combooptDocumentCode_AfterUpdate()
DoCmd.ApplyFilter , "[DocumentCode]=Forms!frmPatientInformation!combooptDocumentCode"
EnableControls Me, acDetail, True
End Sub

the form redisplays the selected matching record and the filter marker on the ribbon shows filtered. If I reset the form to display all records I go back to my 957 starting position but if I make another combo selection the form just blanks and just the background is displayed.

I have attached some images to help

Any help would be greatly appreciated.
 

Attachments

  • start.jpg
    start.jpg
    70.8 KB · Views: 142
  • initial selection.jpg
    initial selection.jpg
    68.6 KB · Views: 138
  • Reset Second Selection.jpg
    Reset Second Selection.jpg
    73.4 KB · Views: 136
Show the Reset code. Also when you reset you should clear the combo box by setting its value to the empty string.
 
Try to compact and repair database and also check for any missing references if you have in any VBA module.


Tools>>>>>References

Also ....

Compile database
Debug>>>>>Compile... from code menu

Khalid
 
Hi
The reset code is

Private Sub btnReset_Click()
Forms!frmPatientInformation!combooptselOwner = Null
Forms!frmPatientInformation!combooptDocumentCode = Null
Forms!frmPatientInformation!combooptDepartment = Null
Me.optSelDirectorate = Null
DoCmd.Requery
DoCmd.ShowAllRecords
On Error GoTo Err_btnReset_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
Exit_btnReset_Click:
Exit Sub
Err_btnReset_Click:
MsgBox Err.Description
Resume Exit_btnReset_Click
End Sub

I have also debuged the code with no problems and compacted and repaired the database with no apparent problems. The references I am not sure about. The list was partially ticked and I don't think I am using anything that was not in the list.

Could it have anything to do with trying to filter a query rather than a table?

Still does not work?
 
Last edited:
Let's amend both procedures. Use Filter and FilterOn properties of the form instead.

Try these:
Code:
Private Sub combooptDocumentCode_AfterUpdate()
    Me.Filter = "[DocumentCode]=Forms!frmPatientInformation!combooptDocumentCode"
    Me.FilterOn = True
    EnableControls Me, acDetail, True
End Sub

Private Sub btnReset_Click()
On Error GoTo Err_btnReset_Click

    With Forms!frmPatientInformation!
        !combooptselOwner = Null
        !combooptDocumentCode = Null
        !combooptDepartment = Null
    End With
    Me.FilterOn = False
    Me.Filter = ""
    Me.optSelDirectorate = Null
'    DoCmd.Requery
'    DoCmd.ShowAllRecords
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
    
Exit_btnReset_Click:
    Exit Sub
Err_btnReset_Click:
    MsgBox Err.Description
    Resume Exit_btnReset_Click

End Sub
Could also show what your EnableControls routine does? Just curious how you're using Me and the acDetail constant.
 
Hi VbaInet

That didn't work. I had to reset the form after opening it before selecting a document code. The initial state was as image 3 and the selection process did not work
 
So what does the EnableControls routine do? Also what is the menuItem method selecting?

Can you post your db?
 
The db is rather large and I cannot see a way to depersonalise it.
The enable controls function has crept in form some other person advising me
Function EnableControls(frm As Form, intSection As Integer, intState As Boolean) As Boolean

' Enable or disable controls in specified section of form.
' Use the Form object, section constant and state arguments
' passed to the EnableControls procedure.

Dim ctl As Control

' Set intState for all controls in specified section.
For Each ctl In frm.Controls
If ctl.Section = intSection Then
On Error Resume Next
ctl.Enabled = intState
Err = 0
End If
Next ctl

EnableControls = True

End Function

Don't think it is doing anything in this situation and the emnu item is microsoft standard
It is as if the filter is working and there is nothing to display, which is not true and previously it always worked the first time to a second always fails.

Thanks for your help
 
Actually, let me get some things clarified.

1. The combo box is on the main form right?
2. Is the form being filtered a subform?
 
The combo box is in the header of the main form and filters the main form. There is a subform displaying the detail and dates linked to the ID of the main form.
 
Replace this line:

Code:
Me.Filter = "[DocumentCode]=" & combooptDocumentCode
 
Last edited:
Syntax error expected end of statement with cursor on the last " Any idea what has changed in 2007. My code worked perfectly in 2003
 
There was a quote at the end, that was a typo. Remove the last quote and see the result.

In relation to your code, nothing has changed. It may be the way 2007 handles the code in the background.
 
That produced a strange result. When I select a document code a parameter query message box is opened with the document code as the text question. Typing in a code and selecting dispalys that document correctly. Resetting and trying another document code the form displays the previously selected code's document?
I have noticed that on opening the from the filtered box at the bottom of the form next to the record selectors shows unfilterd. After resetting it is greyed out and shows no filter?
 
Hi
The reset code is

Private Sub btnReset_Click()
Forms!frmPatientInformation!combooptselOwner = Null
Forms!frmPatientInformation!combooptDocumentCode = Null
Forms!frmPatientInformation!combooptDepartment = Null
Me.optSelDirectorate = Null
DoCmd.Requery
DoCmd.ShowAllRecords
On Error GoTo Err_btnReset_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
Exit_btnReset_Click:
Exit Sub
Err_btnReset_Click:
MsgBox Err.Description
Resume Exit_btnReset_Click
End Sub

I have also debuged the code with no problems and compacted and repaired the database with no apparent problems. The references I am not sure about. The list was partially ticked and I don't think I am using anything that was not in the list.

Could it have anything to do with trying to filter a query rather than a table?

Still does not work?

change this line of code
'DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
with:
Code:
[COLOR="Magenta"]Me.Refresh[/COLOR]

and it should solve your problem.
 
There's already a requery, so no refresh needed.
 
Yes!
you are right SOS, I just noticed that now...:p
but OP wants to refresh the form itself I think and DoCmd.DoMenuItem acFormBar.... produce problem here.
 

Users who are viewing this thread

Back
Top Bottom