"If openargs =" statement syntax needed (1 Viewer)

BarryMK

4 strings are enough
Local time
Today, 03:30
Joined
Oct 15, 2002
Messages
1,350
My form is now opening correctly filtered using OpenArgs but I'd like to set the form caption depending on the filter used. I have three different OpenArgs filters in all opening the same form with different criteria but I can't even get a simple if statement to work. I also tried a Case Select statement using OpenArgs.Value (a guess) but no luck there either.

I thought it would be something simple such as:

Code:
If Me.OpenArgs = "Archived = False" Then
        Me.Caption = "Complaints"
Else
        Me.Caption = "Something else"
End If

I've tried this in OnLoad, OnOpen and OnCurrent but to no avail. Is there some arcane syntax I'm missing or is it something so obvious I can't see it?
 
Some progress but stiill not fully working.

I cleaned out any extraneous code from the form and debugged then placed this back in the OnOpen event. The caption now displays "Something else" when opened from all three filtered buttons on the Switchboard telling me that the "Archived = false" OpenArgs is not being picked up here. Am I missing a bracket or something?

Code:
If Me.OpenArgs = "Archived = False" Then
        Me.Caption = "Complaints"
Else
       Me.Caption = "Something else"
End If
 
Is Archived boolean?
 
i think your expressing the openargs incorrectly

in the openevent of the form put

msgbox(openargs)

then you will see exactly what is being passed into your form

"Archived = False" seems a strange expression
if you want false, just pass false to the form
 
Is Archived boolean?

Hi Rich Yes it's a bound to checkbox on the form


i think your expressing the openargs incorrectly

in the openevent of the form put

msgbox(openargs)

then you will see exactly what is being passed into your form

"Archived = False" seems a strange expression
if you want false, just pass false to the form

Morning Gemma

I tried using your Message box but it prevents the form from opening at all.
Setting the Archived checkbox to false is simply to filter out non-current records

Anyway a bit of background that may help:
The form to be opened frmSearch is bound to a query that pulls all the data from the tables for a particular department.

I have buttons on the switchboard to
1. Open the form to show All current records in the query (those that do not have the Archived checkbox selected) - OpenArgs = "Archived = False"
2. Open all current records which are complaints - OpenArgs = "CountComplaint = 1 AND Archived = False"
3. Open All Archived records (those that have the Archived checkbox selected) - OpenArgs = "Archived = True"

Afraid I'm not sure what you mean by if you want false, just pass false to the form
 
Rich

I made the changes you suggested but the result is still the same!
 
Interestingly I reformatted the OpenArgs on the Switcboard in the same way and got a type mismatch error so I've put it back to how it was and the filtering is back working again.
 
msgbox(openargs)

i dont understand

how can that stop the form opening (unless it throws an error) in which case you might need to trap that with

if isnull(openargs) then
msgbox("No Args")
else
msgbox(openargs)
end if
 
Gemma Very interesting
The no args message box appears, yet the form opens with the correctly filtered information! :confused:
 
when you say filtered at the bottom does it show

eg 1 of 25 (filtered) {ie an active form filter}

or is the filter actually set with criteria in the underlying query {in which case no filter}
 
One of 25 etc

The underlying query only has Dept ID as a criterion.

To test it I first set the query with the filter criteria and ran it noting the number of records, I then deleted the filter criteria from the query and compared the numbers returned on the form with the query results . Bang on. It's crazy.
 
Here are the openargs from the Switchboard. As I said earlier if I set these the way Rich suggested me to code them in the frmSearch I get type mismatch.

Code:
'COMPLAINTS ONLY
Private Sub lblSearchComplaints_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error GoTo Err_LblSearchComplaints_MouseUp_Click
    
Dim stDocName As String
stDocName = "frmSearch"
    Me!Button5.SpecialEffect = 1
        Me!lblSearchComplaints.Visible = True
            DoCmd.Close acForm, "frmSwitchBoard"
                 DoCmd.OpenForm stDocName, , , "CountComplaint = 1 And Archived = False"

Exit_LblSearchComplaints_MouseUp_Click:
    Exit Sub

Err_LblSearchComplaints_MouseUp_Click:
    MsgBox Err.Description
    Resume Exit_LblSearchComplaints_MouseUp_Click
End Sub

'ARCHIVED RECORDS
Private Sub lblArch2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error GoTo Err_lblArch2_MouseUp_Click

Dim stDocName As String
stDocName = "frmSearch"
    Me!Button4.SpecialEffect = 1
        Me!lblArch2.Visible = True
            DoCmd.Close acForm, "frmSwitchBoard"
                DoCmd.OpenForm stDocName, , , "Archived = True"
        
Exit_lblArch2_MouseUp_Click:
    Exit Sub

Err_lblArch2_MouseUp_Click:
    MsgBox Err.Description
    Resume Exit_lblArch2_MouseUp_Click
End Sub
'ALL CURRENT RECORDS
Private Sub Label25_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Me!Button4.SpecialEffect = 2
        Me!Label25.Visible = False
End Sub
'ALL CURRENT RECORDS
Private Sub Label25_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error GoTo Err_Label25_MouseUp_Click
Dim stDocName As String
stDocName = "frmSearch"
    
    Me!Button4.SpecialEffect = 1
        Me!Label25.Visible = True
            DoCmd.Close acForm, "frmSwitchBoard"
                DoCmd.OpenForm stDocName, , , "Archived = False"
 
Exit_Label25_MouseUp_Click:
    Exit Sub

Err_Label25_MouseUp_Click:
    MsgBox Err.Description
    Resume Exit_Label25_MouseUp_Click
End Sub
 
use the intellisense to edit the line, and you will see that you are not entering openargs

what you are entering is a where filter for the form (parameter 4) - openargs is parameter 7

thats why its telling you there are no openargs
 
Ah! Well done and thanks for all your help.

I cannot claim the stupidity entirely as I copied the statement from another post when I was searching!:o

Anyway that's my excuse and I'm sticking with it.

I'll try to get it right tomorrow. I'm off now to demolish a bottle of good wine. I shall definitely raise a glass to you and Rich.
 
that might be why ....

openargs is a STRING i think, so its anything you need to unentagle when the program opens

-could be a username, or a whole range of stuff, so as a string
"archived = false" makes sense


as a where criteria its more likely to be
"archived = " & false

as now it needs formatting to be a sql condition
 
Gemma thanks for the explanation. That helps but can I clarify one more thing please?

Was I wrong in thinking that openargs could be used in this instance like a where clause (an impression I formed from reading loads of posts on openargs) or is openargs only used to set the value of a control in the form as it opens for example prefill textbox txtEmloyee with Joe Bloggs?
 
depends on what you want to do

a criteria will just filter the form to show selected records

-----
but you can use settings in openargs to change anything

eg - depending on the openargs, change the form colours/background image, headings, captions, hide certain controls

even use a different record source, so if you have a choice of sub forms to display on the main form, you can test the openargs, and react accordingly

obviously you can do all this by setting and testing variables, so using openargs or variables, is more a matter of programming taste i think.

--------
so openargs has a lot of flexibility, but of itself it wont do the same thing as a filter automatically, although you could test the openargs, and filter the form based on the setting, programmatically
 

Users who are viewing this thread

Back
Top Bottom