Set Filter from Startup form to another form

G

Guest

I’m working on a startup form for a database going to 35 remote sites. I’m
trying to create a command button to set or apply a filter to a form
(frmMGSP_Deliv) in the database, and then open the database for entering or
editing data. I would like the users to be able to choose their own program
as the filter. The values are in tblLocalProg–ProgID, ProgName, etc. I would
like the filter to remain on until the users remove it specifically, via
another command button on the startup form, as 99 percent of the time they
will enter/edit data only for their own local program

I can open frmMGSP_Deliv for editing, via the menu, with no problem, but I
can’t figure out how to set the filter. Thanks in advance for any
suggestions.
 
G

Guest

Use the OpenArgs argument of the OpenForm method to pass the filter value to
the form.
strFilter = "The Filter Value you Want"
DoCmd.OpenForm "frmMGSP_Deliv",,,,strFilter

Then use the OpenArgs property of the form to set the filter in the Load
event.

If Not (IsNull) Me.OpenArgs Then
Me.Filter = "[FieldToFilter] = '" & Me.OpenArgs & "'"
Me.FilterOn = True
End If
 
G

Guest

Thanks for your help. I can now open the form using a constant, i.e.,

strDocName = "frmMGSP_Deliv"
strFilter = "1"
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

This occurs through a command button on my startup form. Now I’d like to
able to have the users click on this command button, or another one, and have
them choose their own program as the filter to the form. Ideally they would
only have to do this one time, when they first start using the database-that
is, the form would open with the same filter already set every day, so they
don't have to choose their own program every time they use the database.

What do you think of using a command button from the starup form to call a
pop-up form with an unbound combo box that would get their selection, and
then use it to set the form filter? I would appreciate any ideas or comments
you have, regarding where to put code and how to handle the variables.

Thanks again.


Klatuu said:
Use the OpenArgs argument of the OpenForm method to pass the filter value to
the form.
strFilter = "The Filter Value you Want"
DoCmd.OpenForm "frmMGSP_Deliv",,,,strFilter

Then use the OpenArgs property of the form to set the filter in the Load
event.

If Not (IsNull) Me.OpenArgs Then
Me.Filter = "[FieldToFilter] = '" & Me.OpenArgs & "'"
Me.FilterOn = True
End If

RWilly said:
I’m working on a startup form for a database going to 35 remote sites. I’m
trying to create a command button to set or apply a filter to a form
(frmMGSP_Deliv) in the database, and then open the database for entering or
editing data. I would like the users to be able to choose their own program
as the filter. The values are in tblLocalProg–ProgID, ProgName, etc. I would
like the filter to remain on until the users remove it specifically, via
another command button on the startup form, as 99 percent of the time they
will enter/edit data only for their own local program

I can open frmMGSP_Deliv for editing, via the menu, with no problem, but I
can’t figure out how to set the filter. Thanks in advance for any
suggestions.
 
G

Guest

Getting pretty advanced here, aren't we :)

Not that hard, really. All you need to do is create a database property
that you can read each time you need to open the form and load it's value in
the filter. You may also want a button that allows the user to change the
value of the property if they need to change programs.

The first thing you will need to do is create the property. The quick and
easy way is to do it in the immediate window of the the VBA editor. Here are
the two lines of code to type in:

set prop = currentdb.CreateProperty("MyProgram",dbtext,"New")
currentdb.Properties.Append prop

You can change the name of the property by replacing MyProgram with whatever
you want to call it. I use the value New because we will want that later.

Now, just change your code like this:

strDocName = "frmMGSP_Deliv"
strFilter = CurrentDb.Properties("MyProgram")
If strFilter = "New" Then
currentdb.Properties("MyProgram") = inputbox("Enter Program Name")
strFilter = CurrentDb.Properties("MyProgram")
End If
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

If you want the user to be able to change the program, provide a command
button and in the click event:

Dim strNewProgram

strNewProgram = inputbox("Current Program Is " &
Currentdb.Properties("myprogram") & vbnewline & "Change to")

If Len(strNewProgram) > 0 Then
Currentdb.Properties("MyProgram") = strNewProgram
MsgBox "Program Changed to " & strNewProgram
Else
MsgBox "Change Canceled"
End If


RWilly said:
Thanks for your help. I can now open the form using a constant, i.e.,

strDocName = "frmMGSP_Deliv"
strFilter = "1"
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

This occurs through a command button on my startup form. Now I’d like to
able to have the users click on this command button, or another one, and have
them choose their own program as the filter to the form. Ideally they would
only have to do this one time, when they first start using the database-that
is, the form would open with the same filter already set every day, so they
don't have to choose their own program every time they use the database.

What do you think of using a command button from the starup form to call a
pop-up form with an unbound combo box that would get their selection, and
then use it to set the form filter? I would appreciate any ideas or comments
you have, regarding where to put code and how to handle the variables.

Thanks again.


Klatuu said:
Use the OpenArgs argument of the OpenForm method to pass the filter value to
the form.
strFilter = "The Filter Value you Want"
DoCmd.OpenForm "frmMGSP_Deliv",,,,strFilter

Then use the OpenArgs property of the form to set the filter in the Load
event.

If Not (IsNull) Me.OpenArgs Then
Me.Filter = "[FieldToFilter] = '" & Me.OpenArgs & "'"
Me.FilterOn = True
End If

RWilly said:
I’m working on a startup form for a database going to 35 remote sites. I’m
trying to create a command button to set or apply a filter to a form
(frmMGSP_Deliv) in the database, and then open the database for entering or
editing data. I would like the users to be able to choose their own program
as the filter. The values are in tblLocalProg–ProgID, ProgName, etc. I would
like the filter to remain on until the users remove it specifically, via
another command button on the startup form, as 99 percent of the time they
will enter/edit data only for their own local program

I can open frmMGSP_Deliv for editing, via the menu, with no problem, but I
can’t figure out how to set the filter. Thanks in advance for any
suggestions.
 
G

Guest

Thanks for your response. Sorry it took me so long to get back. I tried to
implement the code you were kind enough to send. Once I added

currentdb.Properties.Refresh

to the two lines of code in the Immediate Window it ran without errors, but
I couldn’t get the code in the command button to run without errors. I should
have made a note of the exact error.

Right now I’ve created a form that is close to doing what I want it to. I’ve
got an unbound combo box that shows all the local districts (aka local
programs). One I select a local district, I then run the code below from a
command button on the same form.

Private Sub cmdFilterMGSP_Deliv_Click()
Dim strSQL As String

If Me("cboProgFilter") <> "" Then
' Build SQL String.
strSQL = "((tblLocalProg.[ProgID]" _
& " = " & Me("cboProgFilter") & "))" ‘ProgID is a long integer
End If


If strSQL <> "" Then

' Set the Filter property.
Forms![frmMGSP_Deliv].Filter = strSQL
Forms![frmMGSP_Deliv].FilterOn = True
End If

End Sub

Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenForm "frmMGSP_Deliv"
End Sub

I do have to open frmMGSP_Deliv, which seems clumsy, but the filter on
frmMGSP_Deliv is set. However, it doesn’t stay set when it’s opened the next
time. I’ve commented out the code you sent in your last message, so that
shouldn’t be a problem.

Any suggestions are appreciated. Thanks.


Klatuu said:
Getting pretty advanced here, aren't we :)

Not that hard, really. All you need to do is create a database property
that you can read each time you need to open the form and load it's value in
the filter. You may also want a button that allows the user to change the
value of the property if they need to change programs.

The first thing you will need to do is create the property. The quick and
easy way is to do it in the immediate window of the the VBA editor. Here are
the two lines of code to type in:

set prop = currentdb.CreateProperty("MyProgram",dbtext,"New")
currentdb.Properties.Append prop

You can change the name of the property by replacing MyProgram with whatever
you want to call it. I use the value New because we will want that later.

Now, just change your code like this:

strDocName = "frmMGSP_Deliv"
strFilter = CurrentDb.Properties("MyProgram")
If strFilter = "New" Then
currentdb.Properties("MyProgram") = inputbox("Enter Program Name")
strFilter = CurrentDb.Properties("MyProgram")
End If
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

If you want the user to be able to change the program, provide a command
button and in the click event:

Dim strNewProgram

strNewProgram = inputbox("Current Program Is " &
Currentdb.Properties("myprogram") & vbnewline & "Change to")

If Len(strNewProgram) > 0 Then
Currentdb.Properties("MyProgram") = strNewProgram
MsgBox "Program Changed to " & strNewProgram
Else
MsgBox "Change Canceled"
End If


RWilly said:
Thanks for your help. I can now open the form using a constant, i.e.,

strDocName = "frmMGSP_Deliv"
strFilter = "1"
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

This occurs through a command button on my startup form. Now I’d like to
able to have the users click on this command button, or another one, and have
them choose their own program as the filter to the form. Ideally they would
only have to do this one time, when they first start using the database-that
is, the form would open with the same filter already set every day, so they
don't have to choose their own program every time they use the database.

What do you think of using a command button from the starup form to call a
pop-up form with an unbound combo box that would get their selection, and
then use it to set the form filter? I would appreciate any ideas or comments
you have, regarding where to put code and how to handle the variables.

Thanks again.


Klatuu said:
Use the OpenArgs argument of the OpenForm method to pass the filter value to
the form.
strFilter = "The Filter Value you Want"
DoCmd.OpenForm "frmMGSP_Deliv",,,,strFilter

Then use the OpenArgs property of the form to set the filter in the Load
event.

If Not (IsNull) Me.OpenArgs Then
Me.Filter = "[FieldToFilter] = '" & Me.OpenArgs & "'"
Me.FilterOn = True
End If

:

I’m working on a startup form for a database going to 35 remote sites. I’m
trying to create a command button to set or apply a filter to a form
(frmMGSP_Deliv) in the database, and then open the database for entering or
editing data. I would like the users to be able to choose their own program
as the filter. The values are in tblLocalProg–ProgID, ProgName, etc. I would
like the filter to remain on until the users remove it specifically, via
another command button on the startup form, as 99 percent of the time they
will enter/edit data only for their own local program

I can open frmMGSP_Deliv for editing, via the menu, with no problem, but I
can’t figure out how to set the filter. Thanks in advance for any
suggestions.
 
G

Guest

That will do just fine, in fact in a multi user environment, you may want to
add the userid to the table. Then in the startup, lookup the userid and if
they already have a program defined, use it.

RWilly said:
Thanks for your response. Sorry it took me so long to get back. I tried to
implement the code you were kind enough to send. Once I added

currentdb.Properties.Refresh

to the two lines of code in the Immediate Window it ran without errors, but
I couldn’t get the code in the command button to run without errors. I should
have made a note of the exact error.

Right now I’ve created a form that is close to doing what I want it to. I’ve
got an unbound combo box that shows all the local districts (aka local
programs). One I select a local district, I then run the code below from a
command button on the same form.

Private Sub cmdFilterMGSP_Deliv_Click()
Dim strSQL As String

If Me("cboProgFilter") <> "" Then
' Build SQL String.
strSQL = "((tblLocalProg.[ProgID]" _
& " = " & Me("cboProgFilter") & "))" ‘ProgID is a long integer
End If


If strSQL <> "" Then

' Set the Filter property.
Forms![frmMGSP_Deliv].Filter = strSQL
Forms![frmMGSP_Deliv].FilterOn = True
End If

End Sub

Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenForm "frmMGSP_Deliv"
End Sub

I do have to open frmMGSP_Deliv, which seems clumsy, but the filter on
frmMGSP_Deliv is set. However, it doesn’t stay set when it’s opened the next
time. I’ve commented out the code you sent in your last message, so that
shouldn’t be a problem.

Any suggestions are appreciated. Thanks.


Klatuu said:
Getting pretty advanced here, aren't we :)

Not that hard, really. All you need to do is create a database property
that you can read each time you need to open the form and load it's value in
the filter. You may also want a button that allows the user to change the
value of the property if they need to change programs.

The first thing you will need to do is create the property. The quick and
easy way is to do it in the immediate window of the the VBA editor. Here are
the two lines of code to type in:

set prop = currentdb.CreateProperty("MyProgram",dbtext,"New")
currentdb.Properties.Append prop

You can change the name of the property by replacing MyProgram with whatever
you want to call it. I use the value New because we will want that later.

Now, just change your code like this:

strDocName = "frmMGSP_Deliv"
strFilter = CurrentDb.Properties("MyProgram")
If strFilter = "New" Then
currentdb.Properties("MyProgram") = inputbox("Enter Program Name")
strFilter = CurrentDb.Properties("MyProgram")
End If
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

If you want the user to be able to change the program, provide a command
button and in the click event:

Dim strNewProgram

strNewProgram = inputbox("Current Program Is " &
Currentdb.Properties("myprogram") & vbnewline & "Change to")

If Len(strNewProgram) > 0 Then
Currentdb.Properties("MyProgram") = strNewProgram
MsgBox "Program Changed to " & strNewProgram
Else
MsgBox "Change Canceled"
End If


RWilly said:
Thanks for your help. I can now open the form using a constant, i.e.,

strDocName = "frmMGSP_Deliv"
strFilter = "1"
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

This occurs through a command button on my startup form. Now I’d like to
able to have the users click on this command button, or another one, and have
them choose their own program as the filter to the form. Ideally they would
only have to do this one time, when they first start using the database-that
is, the form would open with the same filter already set every day, so they
don't have to choose their own program every time they use the database.

What do you think of using a command button from the starup form to call a
pop-up form with an unbound combo box that would get their selection, and
then use it to set the form filter? I would appreciate any ideas or comments
you have, regarding where to put code and how to handle the variables.

Thanks again.


:

Use the OpenArgs argument of the OpenForm method to pass the filter value to
the form.
strFilter = "The Filter Value you Want"
DoCmd.OpenForm "frmMGSP_Deliv",,,,strFilter

Then use the OpenArgs property of the form to set the filter in the Load
event.

If Not (IsNull) Me.OpenArgs Then
Me.Filter = "[FieldToFilter] = '" & Me.OpenArgs & "'"
Me.FilterOn = True
End If

:

I’m working on a startup form for a database going to 35 remote sites. I’m
trying to create a command button to set or apply a filter to a form
(frmMGSP_Deliv) in the database, and then open the database for entering or
editing data. I would like the users to be able to choose their own program
as the filter. The values are in tblLocalProg–ProgID, ProgName, etc. I would
like the filter to remain on until the users remove it specifically, via
another command button on the startup form, as 99 percent of the time they
will enter/edit data only for their own local program

I can open frmMGSP_Deliv for editing, via the menu, with no problem, but I
can’t figure out how to set the filter. Thanks in advance for any
suggestions.
 
G

Guest

Thanks for the reply. I was hoping you might have an idea on how to make the
filter set on the data entry/editing forms permanent, or sticky, so the
filters remain until they're removed explicitly. It's important enough that
I'm going back to the code you forwarded and seeing if I can use/adapt it.

Regards.


Klatuu said:
That will do just fine, in fact in a multi user environment, you may want to
add the userid to the table. Then in the startup, lookup the userid and if
they already have a program defined, use it.

RWilly said:
Thanks for your response. Sorry it took me so long to get back. I tried to
implement the code you were kind enough to send. Once I added

currentdb.Properties.Refresh

to the two lines of code in the Immediate Window it ran without errors, but
I couldn’t get the code in the command button to run without errors. I should
have made a note of the exact error.

Right now I’ve created a form that is close to doing what I want it to. I’ve
got an unbound combo box that shows all the local districts (aka local
programs). One I select a local district, I then run the code below from a
command button on the same form.

Private Sub cmdFilterMGSP_Deliv_Click()
Dim strSQL As String

If Me("cboProgFilter") <> "" Then
' Build SQL String.
strSQL = "((tblLocalProg.[ProgID]" _
& " = " & Me("cboProgFilter") & "))" ‘ProgID is a long integer
End If


If strSQL <> "" Then

' Set the Filter property.
Forms![frmMGSP_Deliv].Filter = strSQL
Forms![frmMGSP_Deliv].FilterOn = True
End If

End Sub

Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenForm "frmMGSP_Deliv"
End Sub

I do have to open frmMGSP_Deliv, which seems clumsy, but the filter on
frmMGSP_Deliv is set. However, it doesn’t stay set when it’s opened the next
time. I’ve commented out the code you sent in your last message, so that
shouldn’t be a problem.

Any suggestions are appreciated. Thanks.


Klatuu said:
Getting pretty advanced here, aren't we :)

Not that hard, really. All you need to do is create a database property
that you can read each time you need to open the form and load it's value in
the filter. You may also want a button that allows the user to change the
value of the property if they need to change programs.

The first thing you will need to do is create the property. The quick and
easy way is to do it in the immediate window of the the VBA editor. Here are
the two lines of code to type in:

set prop = currentdb.CreateProperty("MyProgram",dbtext,"New")
currentdb.Properties.Append prop

You can change the name of the property by replacing MyProgram with whatever
you want to call it. I use the value New because we will want that later.

Now, just change your code like this:

strDocName = "frmMGSP_Deliv"
strFilter = CurrentDb.Properties("MyProgram")
If strFilter = "New" Then
currentdb.Properties("MyProgram") = inputbox("Enter Program Name")
strFilter = CurrentDb.Properties("MyProgram")
End If
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

If you want the user to be able to change the program, provide a command
button and in the click event:

Dim strNewProgram

strNewProgram = inputbox("Current Program Is " &
Currentdb.Properties("myprogram") & vbnewline & "Change to")

If Len(strNewProgram) > 0 Then
Currentdb.Properties("MyProgram") = strNewProgram
MsgBox "Program Changed to " & strNewProgram
Else
MsgBox "Change Canceled"
End If


:

Thanks for your help. I can now open the form using a constant, i.e.,

strDocName = "frmMGSP_Deliv"
strFilter = "1"
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

This occurs through a command button on my startup form. Now I’d like to
able to have the users click on this command button, or another one, and have
them choose their own program as the filter to the form. Ideally they would
only have to do this one time, when they first start using the database-that
is, the form would open with the same filter already set every day, so they
don't have to choose their own program every time they use the database.

What do you think of using a command button from the starup form to call a
pop-up form with an unbound combo box that would get their selection, and
then use it to set the form filter? I would appreciate any ideas or comments
you have, regarding where to put code and how to handle the variables.

Thanks again.


:

Use the OpenArgs argument of the OpenForm method to pass the filter value to
the form.
strFilter = "The Filter Value you Want"
DoCmd.OpenForm "frmMGSP_Deliv",,,,strFilter

Then use the OpenArgs property of the form to set the filter in the Load
event.

If Not (IsNull) Me.OpenArgs Then
Me.Filter = "[FieldToFilter] = '" & Me.OpenArgs & "'"
Me.FilterOn = True
End If

:

I’m working on a startup form for a database going to 35 remote sites. I’m
trying to create a command button to set or apply a filter to a form
(frmMGSP_Deliv) in the database, and then open the database for entering or
editing data. I would like the users to be able to choose their own program
as the filter. The values are in tblLocalProg–ProgID, ProgName, etc. I would
like the filter to remain on until the users remove it specifically, via
another command button on the startup form, as 99 percent of the time they
will enter/edit data only for their own local program

I can open frmMGSP_Deliv for editing, via the menu, with no problem, but I
can’t figure out how to set the filter. Thanks in advance for any
suggestions.
 
G

Guest

Using the Database Property method is presistent. The original approach I
suggested would really only be useful if you correctly implement your
applcation so that each user has their own copy of the mdb on their computer.

Using a table will work in a multi user environment regardless of how the
deploy the application.

The primary difference is, that once set, the Property can be read without
any other actions.

If you want to have the program presistent througout the application, make
this the Load event of your start up form. Or, if your start up code is not
a form, change the name of the sub, and execute it somewhere in your start up
code. It will ensure the property exists and create it if it does not.

Private Sub Form_Load()
Dim strPrg As String

On Error GoTo Form_Load_Error

strPrg = CurrentDb.Properties("MyProgram")

Form_Load_Exit:

On Error Resume Next

Exit Sub

Form_Load_Error:

If Err.Number = 3270 Then
strPrg = StartProgram(False)
Else
MsgBox "Error " & Err.Number & " (" & Err.DESCRIPTION & _
") in procedure Form_Load of VBA Document Form_frmMasterSubTest"
End If
GoTo Form_Load_Exit

End Sub

Here is the function it calls if the program does not exits:

Private Function StartProgram(blnPropExists) As String
Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

With CurrentDb
If blnPropExists Then
.Properties("MyProgram") = strProgName
Else
Set Prop = .CreateProperty("MyProgram", dbText, strProgName)
.Properties.Append Prop
End If

End With
StartProgram = strProgName
End Function

Now all that is necessary is to set the filter for each form where you want
the filtering to apply. Put this code in the Load Event of the forms:

Me.Filter = "[Program] = '" & Currentdb.Properties("MyProgram") & "'"
Me.FilterOn = True

RWilly said:
Thanks for the reply. I was hoping you might have an idea on how to make the
filter set on the data entry/editing forms permanent, or sticky, so the
filters remain until they're removed explicitly. It's important enough that
I'm going back to the code you forwarded and seeing if I can use/adapt it.

Regards.


Klatuu said:
That will do just fine, in fact in a multi user environment, you may want to
add the userid to the table. Then in the startup, lookup the userid and if
they already have a program defined, use it.

RWilly said:
Thanks for your response. Sorry it took me so long to get back. I tried to
implement the code you were kind enough to send. Once I added

currentdb.Properties.Refresh

to the two lines of code in the Immediate Window it ran without errors, but
I couldn’t get the code in the command button to run without errors. I should
have made a note of the exact error.

Right now I’ve created a form that is close to doing what I want it to. I’ve
got an unbound combo box that shows all the local districts (aka local
programs). One I select a local district, I then run the code below from a
command button on the same form.

Private Sub cmdFilterMGSP_Deliv_Click()
Dim strSQL As String

If Me("cboProgFilter") <> "" Then
' Build SQL String.
strSQL = "((tblLocalProg.[ProgID]" _
& " = " & Me("cboProgFilter") & "))" ‘ProgID is a long integer
End If


If strSQL <> "" Then

' Set the Filter property.
Forms![frmMGSP_Deliv].Filter = strSQL
Forms![frmMGSP_Deliv].FilterOn = True
End If

End Sub

Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenForm "frmMGSP_Deliv"
End Sub

I do have to open frmMGSP_Deliv, which seems clumsy, but the filter on
frmMGSP_Deliv is set. However, it doesn’t stay set when it’s opened the next
time. I’ve commented out the code you sent in your last message, so that
shouldn’t be a problem.

Any suggestions are appreciated. Thanks.


:

Getting pretty advanced here, aren't we :)

Not that hard, really. All you need to do is create a database property
that you can read each time you need to open the form and load it's value in
the filter. You may also want a button that allows the user to change the
value of the property if they need to change programs.

The first thing you will need to do is create the property. The quick and
easy way is to do it in the immediate window of the the VBA editor. Here are
the two lines of code to type in:

set prop = currentdb.CreateProperty("MyProgram",dbtext,"New")
currentdb.Properties.Append prop

You can change the name of the property by replacing MyProgram with whatever
you want to call it. I use the value New because we will want that later.

Now, just change your code like this:

strDocName = "frmMGSP_Deliv"
strFilter = CurrentDb.Properties("MyProgram")
If strFilter = "New" Then
currentdb.Properties("MyProgram") = inputbox("Enter Program Name")
strFilter = CurrentDb.Properties("MyProgram")
End If
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

If you want the user to be able to change the program, provide a command
button and in the click event:

Dim strNewProgram

strNewProgram = inputbox("Current Program Is " &
Currentdb.Properties("myprogram") & vbnewline & "Change to")

If Len(strNewProgram) > 0 Then
Currentdb.Properties("MyProgram") = strNewProgram
MsgBox "Program Changed to " & strNewProgram
Else
MsgBox "Change Canceled"
End If


:

Thanks for your help. I can now open the form using a constant, i.e.,

strDocName = "frmMGSP_Deliv"
strFilter = "1"
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

This occurs through a command button on my startup form. Now I’d like to
able to have the users click on this command button, or another one, and have
them choose their own program as the filter to the form. Ideally they would
only have to do this one time, when they first start using the database-that
is, the form would open with the same filter already set every day, so they
don't have to choose their own program every time they use the database.

What do you think of using a command button from the starup form to call a
pop-up form with an unbound combo box that would get their selection, and
then use it to set the form filter? I would appreciate any ideas or comments
you have, regarding where to put code and how to handle the variables.

Thanks again.


:

Use the OpenArgs argument of the OpenForm method to pass the filter value to
the form.
strFilter = "The Filter Value you Want"
DoCmd.OpenForm "frmMGSP_Deliv",,,,strFilter

Then use the OpenArgs property of the form to set the filter in the Load
event.

If Not (IsNull) Me.OpenArgs Then
Me.Filter = "[FieldToFilter] = '" & Me.OpenArgs & "'"
Me.FilterOn = True
End If

:

I’m working on a startup form for a database going to 35 remote sites. I’m
trying to create a command button to set or apply a filter to a form
(frmMGSP_Deliv) in the database, and then open the database for entering or
editing data. I would like the users to be able to choose their own program
as the filter. The values are in tblLocalProg–ProgID, ProgName, etc. I would
like the filter to remain on until the users remove it specifically, via
another command button on the startup form, as 99 percent of the time they
will enter/edit data only for their own local program

I can open frmMGSP_Deliv for editing, via the menu, with no problem, but I
can’t figure out how to set the filter. Thanks in advance for any
suggestions.
 
G

Guest

I'm back to using the original approach you suggested, as each user will have
their own copy of the mdb (front and back end, 30 offices across the state
with no network but the Internet).

On using the code from your last message, I get

run-time error "13"
type mismatch

Debug points to

Set Prop = .CreateProperty("MyProgram", dbText, strProgName)

I've tried specifying an object for CreateProperty, but I don't really know
what I'm doing in this case. I really appreciate your patience, and any help
or suggestions you have.

Klatuu said:
Using the Database Property method is presistent. The original approach I
suggested would really only be useful if you correctly implement your
applcation so that each user has their own copy of the mdb on their computer.

Using a table will work in a multi user environment regardless of how the
deploy the application.

The primary difference is, that once set, the Property can be read without
any other actions.

If you want to have the program presistent througout the application, make
this the Load event of your start up form. Or, if your start up code is not
a form, change the name of the sub, and execute it somewhere in your start up
code. It will ensure the property exists and create it if it does not.

Private Sub Form_Load()
Dim strPrg As String

On Error GoTo Form_Load_Error

strPrg = CurrentDb.Properties("MyProgram")

Form_Load_Exit:

On Error Resume Next

Exit Sub

Form_Load_Error:

If Err.Number = 3270 Then
strPrg = StartProgram(False)
Else
MsgBox "Error " & Err.Number & " (" & Err.DESCRIPTION & _
") in procedure Form_Load of VBA Document Form_frmMasterSubTest"
End If
GoTo Form_Load_Exit

End Sub

Here is the function it calls if the program does not exits:

Private Function StartProgram(blnPropExists) As String
Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

With CurrentDb
If blnPropExists Then
.Properties("MyProgram") = strProgName
Else
Set Prop = .CreateProperty("MyProgram", dbText, strProgName)
.Properties.Append Prop
End If

End With
StartProgram = strProgName
End Function

Now all that is necessary is to set the filter for each form where you want
the filtering to apply. Put this code in the Load Event of the forms:

Me.Filter = "[Program] = '" & Currentdb.Properties("MyProgram") & "'"
Me.FilterOn = True

RWilly said:
Thanks for the reply. I was hoping you might have an idea on how to make the
filter set on the data entry/editing forms permanent, or sticky, so the
filters remain until they're removed explicitly. It's important enough that
I'm going back to the code you forwarded and seeing if I can use/adapt it.

Regards.


Klatuu said:
That will do just fine, in fact in a multi user environment, you may want to
add the userid to the table. Then in the startup, lookup the userid and if
they already have a program defined, use it.

:

Thanks for your response. Sorry it took me so long to get back. I tried to
implement the code you were kind enough to send. Once I added

currentdb.Properties.Refresh

to the two lines of code in the Immediate Window it ran without errors, but
I couldn’t get the code in the command button to run without errors. I should
have made a note of the exact error.

Right now I’ve created a form that is close to doing what I want it to. I’ve
got an unbound combo box that shows all the local districts (aka local
programs). One I select a local district, I then run the code below from a
command button on the same form.

Private Sub cmdFilterMGSP_Deliv_Click()
Dim strSQL As String

If Me("cboProgFilter") <> "" Then
' Build SQL String.
strSQL = "((tblLocalProg.[ProgID]" _
& " = " & Me("cboProgFilter") & "))" ‘ProgID is a long integer
End If


If strSQL <> "" Then

' Set the Filter property.
Forms![frmMGSP_Deliv].Filter = strSQL
Forms![frmMGSP_Deliv].FilterOn = True
End If

End Sub

Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenForm "frmMGSP_Deliv"
End Sub

I do have to open frmMGSP_Deliv, which seems clumsy, but the filter on
frmMGSP_Deliv is set. However, it doesn’t stay set when it’s opened the next
time. I’ve commented out the code you sent in your last message, so that
shouldn’t be a problem.

Any suggestions are appreciated. Thanks.


:

Getting pretty advanced here, aren't we :)

Not that hard, really. All you need to do is create a database property
that you can read each time you need to open the form and load it's value in
the filter. You may also want a button that allows the user to change the
value of the property if they need to change programs.

The first thing you will need to do is create the property. The quick and
easy way is to do it in the immediate window of the the VBA editor. Here are
the two lines of code to type in:

set prop = currentdb.CreateProperty("MyProgram",dbtext,"New")
currentdb.Properties.Append prop

You can change the name of the property by replacing MyProgram with whatever
you want to call it. I use the value New because we will want that later.

Now, just change your code like this:

strDocName = "frmMGSP_Deliv"
strFilter = CurrentDb.Properties("MyProgram")
If strFilter = "New" Then
currentdb.Properties("MyProgram") = inputbox("Enter Program Name")
strFilter = CurrentDb.Properties("MyProgram")
End If
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

If you want the user to be able to change the program, provide a command
button and in the click event:

Dim strNewProgram

strNewProgram = inputbox("Current Program Is " &
Currentdb.Properties("myprogram") & vbnewline & "Change to")

If Len(strNewProgram) > 0 Then
Currentdb.Properties("MyProgram") = strNewProgram
MsgBox "Program Changed to " & strNewProgram
Else
MsgBox "Change Canceled"
End If


:

Thanks for your help. I can now open the form using a constant, i.e.,

strDocName = "frmMGSP_Deliv"
strFilter = "1"
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

This occurs through a command button on my startup form. Now I’d like to
able to have the users click on this command button, or another one, and have
them choose their own program as the filter to the form. Ideally they would
only have to do this one time, when they first start using the database-that
is, the form would open with the same filter already set every day, so they
don't have to choose their own program every time they use the database.

What do you think of using a command button from the starup form to call a
pop-up form with an unbound combo box that would get their selection, and
then use it to set the form filter? I would appreciate any ideas or comments
you have, regarding where to put code and how to handle the variables.

Thanks again.


:

Use the OpenArgs argument of the OpenForm method to pass the filter value to
the form.
strFilter = "The Filter Value you Want"
DoCmd.OpenForm "frmMGSP_Deliv",,,,strFilter

Then use the OpenArgs property of the form to set the filter in the Load
event.

If Not (IsNull) Me.OpenArgs Then
Me.Filter = "[FieldToFilter] = '" & Me.OpenArgs & "'"
Me.FilterOn = True
End If

:

I’m working on a startup form for a database going to 35 remote sites. I’m
trying to create a command button to set or apply a filter to a form
(frmMGSP_Deliv) in the database, and then open the database for entering or
editing data. I would like the users to be able to choose their own program
as the filter. The values are in tblLocalProg–ProgID, ProgName, etc. I would
like the filter to remain on until the users remove it specifically, via
another command button on the startup form, as 99 percent of the time they
will enter/edit data only for their own local program

I can open frmMGSP_Deliv for editing, via the menu, with no problem, but I
can’t figure out how to set the filter. Thanks in advance for any
suggestions.
 
G

Guest

I've should have added in my last message that the input box opens fine, and
the variable stores whatever I enter into it, according to Debug.

Klatuu said:
Using the Database Property method is presistent. The original approach I
suggested would really only be useful if you correctly implement your
applcation so that each user has their own copy of the mdb on their computer.

Using a table will work in a multi user environment regardless of how the
deploy the application.

The primary difference is, that once set, the Property can be read without
any other actions.

If you want to have the program presistent througout the application, make
this the Load event of your start up form. Or, if your start up code is not
a form, change the name of the sub, and execute it somewhere in your start up
code. It will ensure the property exists and create it if it does not.

Private Sub Form_Load()
Dim strPrg As String

On Error GoTo Form_Load_Error

strPrg = CurrentDb.Properties("MyProgram")

Form_Load_Exit:

On Error Resume Next

Exit Sub

Form_Load_Error:

If Err.Number = 3270 Then
strPrg = StartProgram(False)
Else
MsgBox "Error " & Err.Number & " (" & Err.DESCRIPTION & _
") in procedure Form_Load of VBA Document Form_frmMasterSubTest"
End If
GoTo Form_Load_Exit

End Sub

Here is the function it calls if the program does not exits:

Private Function StartProgram(blnPropExists) As String
Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

With CurrentDb
If blnPropExists Then
.Properties("MyProgram") = strProgName
Else
Set Prop = .CreateProperty("MyProgram", dbText, strProgName)
.Properties.Append Prop
End If

End With
StartProgram = strProgName
End Function

Now all that is necessary is to set the filter for each form where you want
the filtering to apply. Put this code in the Load Event of the forms:

Me.Filter = "[Program] = '" & Currentdb.Properties("MyProgram") & "'"
Me.FilterOn = True

RWilly said:
Thanks for the reply. I was hoping you might have an idea on how to make the
filter set on the data entry/editing forms permanent, or sticky, so the
filters remain until they're removed explicitly. It's important enough that
I'm going back to the code you forwarded and seeing if I can use/adapt it.

Regards.


Klatuu said:
That will do just fine, in fact in a multi user environment, you may want to
add the userid to the table. Then in the startup, lookup the userid and if
they already have a program defined, use it.

:

Thanks for your response. Sorry it took me so long to get back. I tried to
implement the code you were kind enough to send. Once I added

currentdb.Properties.Refresh

to the two lines of code in the Immediate Window it ran without errors, but
I couldn’t get the code in the command button to run without errors. I should
have made a note of the exact error.

Right now I’ve created a form that is close to doing what I want it to. I’ve
got an unbound combo box that shows all the local districts (aka local
programs). One I select a local district, I then run the code below from a
command button on the same form.

Private Sub cmdFilterMGSP_Deliv_Click()
Dim strSQL As String

If Me("cboProgFilter") <> "" Then
' Build SQL String.
strSQL = "((tblLocalProg.[ProgID]" _
& " = " & Me("cboProgFilter") & "))" ‘ProgID is a long integer
End If


If strSQL <> "" Then

' Set the Filter property.
Forms![frmMGSP_Deliv].Filter = strSQL
Forms![frmMGSP_Deliv].FilterOn = True
End If

End Sub

Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenForm "frmMGSP_Deliv"
End Sub

I do have to open frmMGSP_Deliv, which seems clumsy, but the filter on
frmMGSP_Deliv is set. However, it doesn’t stay set when it’s opened the next
time. I’ve commented out the code you sent in your last message, so that
shouldn’t be a problem.

Any suggestions are appreciated. Thanks.


:

Getting pretty advanced here, aren't we :)

Not that hard, really. All you need to do is create a database property
that you can read each time you need to open the form and load it's value in
the filter. You may also want a button that allows the user to change the
value of the property if they need to change programs.

The first thing you will need to do is create the property. The quick and
easy way is to do it in the immediate window of the the VBA editor. Here are
the two lines of code to type in:

set prop = currentdb.CreateProperty("MyProgram",dbtext,"New")
currentdb.Properties.Append prop

You can change the name of the property by replacing MyProgram with whatever
you want to call it. I use the value New because we will want that later.

Now, just change your code like this:

strDocName = "frmMGSP_Deliv"
strFilter = CurrentDb.Properties("MyProgram")
If strFilter = "New" Then
currentdb.Properties("MyProgram") = inputbox("Enter Program Name")
strFilter = CurrentDb.Properties("MyProgram")
End If
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

If you want the user to be able to change the program, provide a command
button and in the click event:

Dim strNewProgram

strNewProgram = inputbox("Current Program Is " &
Currentdb.Properties("myprogram") & vbnewline & "Change to")

If Len(strNewProgram) > 0 Then
Currentdb.Properties("MyProgram") = strNewProgram
MsgBox "Program Changed to " & strNewProgram
Else
MsgBox "Change Canceled"
End If


:

Thanks for your help. I can now open the form using a constant, i.e.,

strDocName = "frmMGSP_Deliv"
strFilter = "1"
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

This occurs through a command button on my startup form. Now I’d like to
able to have the users click on this command button, or another one, and have
them choose their own program as the filter to the form. Ideally they would
only have to do this one time, when they first start using the database-that
is, the form would open with the same filter already set every day, so they
don't have to choose their own program every time they use the database.

What do you think of using a command button from the starup form to call a
pop-up form with an unbound combo box that would get their selection, and
then use it to set the form filter? I would appreciate any ideas or comments
you have, regarding where to put code and how to handle the variables.

Thanks again.


:

Use the OpenArgs argument of the OpenForm method to pass the filter value to
the form.
strFilter = "The Filter Value you Want"
DoCmd.OpenForm "frmMGSP_Deliv",,,,strFilter

Then use the OpenArgs property of the form to set the filter in the Load
event.

If Not (IsNull) Me.OpenArgs Then
Me.Filter = "[FieldToFilter] = '" & Me.OpenArgs & "'"
Me.FilterOn = True
End If

:

I’m working on a startup form for a database going to 35 remote sites. I’m
trying to create a command button to set or apply a filter to a form
(frmMGSP_Deliv) in the database, and then open the database for entering or
editing data. I would like the users to be able to choose their own program
as the filter. The values are in tblLocalProg–ProgID, ProgName, etc. I would
like the filter to remain on until the users remove it specifically, via
another command button on the startup form, as 99 percent of the time they
will enter/edit data only for their own local program

I can open frmMGSP_Deliv for editing, via the menu, with no problem, but I
can’t figure out how to set the filter. Thanks in advance for any
suggestions.
 
G

Guest

Post back with the all the code as you have it. I tested it and it does
work. There must be some error in copying and pasting the code.

RWilly said:
I'm back to using the original approach you suggested, as each user will have
their own copy of the mdb (front and back end, 30 offices across the state
with no network but the Internet).

On using the code from your last message, I get

run-time error "13"
type mismatch

Debug points to

Set Prop = .CreateProperty("MyProgram", dbText, strProgName)

I've tried specifying an object for CreateProperty, but I don't really know
what I'm doing in this case. I really appreciate your patience, and any help
or suggestions you have.

Klatuu said:
Using the Database Property method is presistent. The original approach I
suggested would really only be useful if you correctly implement your
applcation so that each user has their own copy of the mdb on their computer.

Using a table will work in a multi user environment regardless of how the
deploy the application.

The primary difference is, that once set, the Property can be read without
any other actions.

If you want to have the program presistent througout the application, make
this the Load event of your start up form. Or, if your start up code is not
a form, change the name of the sub, and execute it somewhere in your start up
code. It will ensure the property exists and create it if it does not.

Private Sub Form_Load()
Dim strPrg As String

On Error GoTo Form_Load_Error

strPrg = CurrentDb.Properties("MyProgram")

Form_Load_Exit:

On Error Resume Next

Exit Sub

Form_Load_Error:

If Err.Number = 3270 Then
strPrg = StartProgram(False)
Else
MsgBox "Error " & Err.Number & " (" & Err.DESCRIPTION & _
") in procedure Form_Load of VBA Document Form_frmMasterSubTest"
End If
GoTo Form_Load_Exit

End Sub

Here is the function it calls if the program does not exits:

Private Function StartProgram(blnPropExists) As String
Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

With CurrentDb
If blnPropExists Then
.Properties("MyProgram") = strProgName
Else
Set Prop = .CreateProperty("MyProgram", dbText, strProgName)
.Properties.Append Prop
End If

End With
StartProgram = strProgName
End Function

Now all that is necessary is to set the filter for each form where you want
the filtering to apply. Put this code in the Load Event of the forms:

Me.Filter = "[Program] = '" & Currentdb.Properties("MyProgram") & "'"
Me.FilterOn = True

RWilly said:
Thanks for the reply. I was hoping you might have an idea on how to make the
filter set on the data entry/editing forms permanent, or sticky, so the
filters remain until they're removed explicitly. It's important enough that
I'm going back to the code you forwarded and seeing if I can use/adapt it.

Regards.


:

That will do just fine, in fact in a multi user environment, you may want to
add the userid to the table. Then in the startup, lookup the userid and if
they already have a program defined, use it.

:

Thanks for your response. Sorry it took me so long to get back. I tried to
implement the code you were kind enough to send. Once I added

currentdb.Properties.Refresh

to the two lines of code in the Immediate Window it ran without errors, but
I couldn’t get the code in the command button to run without errors. I should
have made a note of the exact error.

Right now I’ve created a form that is close to doing what I want it to. I’ve
got an unbound combo box that shows all the local districts (aka local
programs). One I select a local district, I then run the code below from a
command button on the same form.

Private Sub cmdFilterMGSP_Deliv_Click()
Dim strSQL As String

If Me("cboProgFilter") <> "" Then
' Build SQL String.
strSQL = "((tblLocalProg.[ProgID]" _
& " = " & Me("cboProgFilter") & "))" ‘ProgID is a long integer
End If


If strSQL <> "" Then

' Set the Filter property.
Forms![frmMGSP_Deliv].Filter = strSQL
Forms![frmMGSP_Deliv].FilterOn = True
End If

End Sub

Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenForm "frmMGSP_Deliv"
End Sub

I do have to open frmMGSP_Deliv, which seems clumsy, but the filter on
frmMGSP_Deliv is set. However, it doesn’t stay set when it’s opened the next
time. I’ve commented out the code you sent in your last message, so that
shouldn’t be a problem.

Any suggestions are appreciated. Thanks.


:

Getting pretty advanced here, aren't we :)

Not that hard, really. All you need to do is create a database property
that you can read each time you need to open the form and load it's value in
the filter. You may also want a button that allows the user to change the
value of the property if they need to change programs.

The first thing you will need to do is create the property. The quick and
easy way is to do it in the immediate window of the the VBA editor. Here are
the two lines of code to type in:

set prop = currentdb.CreateProperty("MyProgram",dbtext,"New")
currentdb.Properties.Append prop

You can change the name of the property by replacing MyProgram with whatever
you want to call it. I use the value New because we will want that later.

Now, just change your code like this:

strDocName = "frmMGSP_Deliv"
strFilter = CurrentDb.Properties("MyProgram")
If strFilter = "New" Then
currentdb.Properties("MyProgram") = inputbox("Enter Program Name")
strFilter = CurrentDb.Properties("MyProgram")
End If
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

If you want the user to be able to change the program, provide a command
button and in the click event:

Dim strNewProgram

strNewProgram = inputbox("Current Program Is " &
Currentdb.Properties("myprogram") & vbnewline & "Change to")

If Len(strNewProgram) > 0 Then
Currentdb.Properties("MyProgram") = strNewProgram
MsgBox "Program Changed to " & strNewProgram
Else
MsgBox "Change Canceled"
End If


:

Thanks for your help. I can now open the form using a constant, i.e.,

strDocName = "frmMGSP_Deliv"
strFilter = "1"
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

This occurs through a command button on my startup form. Now I’d like to
able to have the users click on this command button, or another one, and have
them choose their own program as the filter to the form. Ideally they would
only have to do this one time, when they first start using the database-that
is, the form would open with the same filter already set every day, so they
don't have to choose their own program every time they use the database.

What do you think of using a command button from the starup form to call a
pop-up form with an unbound combo box that would get their selection, and
then use it to set the form filter? I would appreciate any ideas or comments
you have, regarding where to put code and how to handle the variables.

Thanks again.


:

Use the OpenArgs argument of the OpenForm method to pass the filter value to
the form.
strFilter = "The Filter Value you Want"
DoCmd.OpenForm "frmMGSP_Deliv",,,,strFilter

Then use the OpenArgs property of the form to set the filter in the Load
event.

If Not (IsNull) Me.OpenArgs Then
Me.Filter = "[FieldToFilter] = '" & Me.OpenArgs & "'"
Me.FilterOn = True
End If

:

I’m working on a startup form for a database going to 35 remote sites. I’m
trying to create a command button to set or apply a filter to a form
(frmMGSP_Deliv) in the database, and then open the database for entering or
editing data. I would like the users to be able to choose their own program
as the filter. The values are in tblLocalProg–ProgID, ProgName, etc. I would
like the filter to remain on until the users remove it specifically, via
another command button on the startup form, as 99 percent of the time they
will enter/edit data only for their own local program

I can open frmMGSP_Deliv for editing, via the menu, with no problem, but I
can’t figure out how to set the filter. Thanks in advance for any
suggestions.
 
G

Guest

Here is all the code from the Load Event and the Function
*********************

Private Sub Form_Load()
Dim strPrg As String

On Error GoTo Form_Load_Error

strPrg = CurrentDb.Properties("MyProgram")

Form_Load_Exit:

On Error Resume Next

Exit Sub

Form_Load_Error:

If Err.Number = 3270 Then
strPrg = StartProgram(False)
Else
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure Form_Load of VBA Document Form_frmMasterSubTest"
End If
GoTo Form_Load_Exit

End Sub
' Here is the function it calls if the program does not exits:

Private Function StartProgram(blnPropExists) As String
Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

With CurrentDb
If blnPropExists Then
.Properties("MyProgram") = strProgName
Else
Set Prop = .CreateProperty("MyProgram", dbText, strProgName)
.Properties.Append Prop
End If
End With

StartProgram = strProgName
End Function

***************************
Thanks again


Klatuu said:
Post back with the all the code as you have it. I tested it and it does
work. There must be some error in copying and pasting the code.

RWilly said:
I'm back to using the original approach you suggested, as each user will have
their own copy of the mdb (front and back end, 30 offices across the state
with no network but the Internet).

On using the code from your last message, I get

run-time error "13"
type mismatch

Debug points to

Set Prop = .CreateProperty("MyProgram", dbText, strProgName)

I've tried specifying an object for CreateProperty, but I don't really know
what I'm doing in this case. I really appreciate your patience, and any help
or suggestions you have.

Klatuu said:
Using the Database Property method is presistent. The original approach I
suggested would really only be useful if you correctly implement your
applcation so that each user has their own copy of the mdb on their computer.

Using a table will work in a multi user environment regardless of how the
deploy the application.

The primary difference is, that once set, the Property can be read without
any other actions.

If you want to have the program presistent througout the application, make
this the Load event of your start up form. Or, if your start up code is not
a form, change the name of the sub, and execute it somewhere in your start up
code. It will ensure the property exists and create it if it does not.

Private Sub Form_Load()
Dim strPrg As String

On Error GoTo Form_Load_Error

strPrg = CurrentDb.Properties("MyProgram")

Form_Load_Exit:

On Error Resume Next

Exit Sub

Form_Load_Error:

If Err.Number = 3270 Then
strPrg = StartProgram(False)
Else
MsgBox "Error " & Err.Number & " (" & Err.DESCRIPTION & _
") in procedure Form_Load of VBA Document Form_frmMasterSubTest"
End If
GoTo Form_Load_Exit

End Sub

Here is the function it calls if the program does not exits:

Private Function StartProgram(blnPropExists) As String
Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

With CurrentDb
If blnPropExists Then
.Properties("MyProgram") = strProgName
Else
Set Prop = .CreateProperty("MyProgram", dbText, strProgName)
.Properties.Append Prop
End If

End With
StartProgram = strProgName
End Function

Now all that is necessary is to set the filter for each form where you want
the filtering to apply. Put this code in the Load Event of the forms:

Me.Filter = "[Program] = '" & Currentdb.Properties("MyProgram") & "'"
Me.FilterOn = True

:

Thanks for the reply. I was hoping you might have an idea on how to make the
filter set on the data entry/editing forms permanent, or sticky, so the
filters remain until they're removed explicitly. It's important enough that
I'm going back to the code you forwarded and seeing if I can use/adapt it.

Regards.


:

That will do just fine, in fact in a multi user environment, you may want to
add the userid to the table. Then in the startup, lookup the userid and if
they already have a program defined, use it.

:

Thanks for your response. Sorry it took me so long to get back. I tried to
implement the code you were kind enough to send. Once I added

currentdb.Properties.Refresh

to the two lines of code in the Immediate Window it ran without errors, but
I couldn’t get the code in the command button to run without errors. I should
have made a note of the exact error.

Right now I’ve created a form that is close to doing what I want it to. I’ve
got an unbound combo box that shows all the local districts (aka local
programs). One I select a local district, I then run the code below from a
command button on the same form.

Private Sub cmdFilterMGSP_Deliv_Click()
Dim strSQL As String

If Me("cboProgFilter") <> "" Then
' Build SQL String.
strSQL = "((tblLocalProg.[ProgID]" _
& " = " & Me("cboProgFilter") & "))" ‘ProgID is a long integer
End If


If strSQL <> "" Then

' Set the Filter property.
Forms![frmMGSP_Deliv].Filter = strSQL
Forms![frmMGSP_Deliv].FilterOn = True
End If

End Sub

Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenForm "frmMGSP_Deliv"
End Sub

I do have to open frmMGSP_Deliv, which seems clumsy, but the filter on
frmMGSP_Deliv is set. However, it doesn’t stay set when it’s opened the next
time. I’ve commented out the code you sent in your last message, so that
shouldn’t be a problem.

Any suggestions are appreciated. Thanks.


:

Getting pretty advanced here, aren't we :)

Not that hard, really. All you need to do is create a database property
that you can read each time you need to open the form and load it's value in
the filter. You may also want a button that allows the user to change the
value of the property if they need to change programs.

The first thing you will need to do is create the property. The quick and
easy way is to do it in the immediate window of the the VBA editor. Here are
the two lines of code to type in:

set prop = currentdb.CreateProperty("MyProgram",dbtext,"New")
currentdb.Properties.Append prop

You can change the name of the property by replacing MyProgram with whatever
you want to call it. I use the value New because we will want that later.

Now, just change your code like this:

strDocName = "frmMGSP_Deliv"
strFilter = CurrentDb.Properties("MyProgram")
If strFilter = "New" Then
currentdb.Properties("MyProgram") = inputbox("Enter Program Name")
strFilter = CurrentDb.Properties("MyProgram")
End If
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

If you want the user to be able to change the program, provide a command
button and in the click event:

Dim strNewProgram

strNewProgram = inputbox("Current Program Is " &
Currentdb.Properties("myprogram") & vbnewline & "Change to")

If Len(strNewProgram) > 0 Then
Currentdb.Properties("MyProgram") = strNewProgram
MsgBox "Program Changed to " & strNewProgram
Else
MsgBox "Change Canceled"
End If


:

Thanks for your help. I can now open the form using a constant, i.e.,

strDocName = "frmMGSP_Deliv"
strFilter = "1"
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

This occurs through a command button on my startup form. Now I’d like to
able to have the users click on this command button, or another one, and have
them choose their own program as the filter to the form. Ideally they would
only have to do this one time, when they first start using the database-that
is, the form would open with the same filter already set every day, so they
don't have to choose their own program every time they use the database.

What do you think of using a command button from the starup form to call a
pop-up form with an unbound combo box that would get their selection, and
then use it to set the form filter? I would appreciate any ideas or comments
you have, regarding where to put code and how to handle the variables.

Thanks again.


:

Use the OpenArgs argument of the OpenForm method to pass the filter value to
the form.
strFilter = "The Filter Value you Want"
DoCmd.OpenForm "frmMGSP_Deliv",,,,strFilter

Then use the OpenArgs property of the form to set the filter in the Load
event.

If Not (IsNull) Me.OpenArgs Then
Me.Filter = "[FieldToFilter] = '" & Me.OpenArgs & "'"
Me.FilterOn = True
End If

:

I’m working on a startup form for a database going to 35 remote sites. I’m
trying to create a command button to set or apply a filter to a form
(frmMGSP_Deliv) in the database, and then open the database for entering or
editing data. I would like the users to be able to choose their own program
as the filter. The values are in tblLocalProg–ProgID, ProgName, etc. I would
like the filter to remain on until the users remove it specifically, via
another command button on the startup form, as 99 percent of the time they
will enter/edit data only for their own local program

I can open frmMGSP_Deliv for editing, via the menu, with no problem, but I
can’t figure out how to set the filter. Thanks in advance for any
suggestions.
 
G

Guest

This is very wierd. You code is exactly as I sent it. I even copied yours
and replaced mine, and it still works correctly.
There is a Property object established that is in the line
Dim Prop As Propery

Try compiling your code to see if there are any errors.

RWilly said:
Here is all the code from the Load Event and the Function
*********************

Private Sub Form_Load()
Dim strPrg As String

On Error GoTo Form_Load_Error

strPrg = CurrentDb.Properties("MyProgram")

Form_Load_Exit:

On Error Resume Next

Exit Sub

Form_Load_Error:

If Err.Number = 3270 Then
strPrg = StartProgram(False)
Else
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure Form_Load of VBA Document Form_frmMasterSubTest"
End If
GoTo Form_Load_Exit

End Sub
' Here is the function it calls if the program does not exits:

Private Function StartProgram(blnPropExists) As String
Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

With CurrentDb
If blnPropExists Then
.Properties("MyProgram") = strProgName
Else
Set Prop = .CreateProperty("MyProgram", dbText, strProgName)
.Properties.Append Prop
End If
End With

StartProgram = strProgName
End Function

***************************
Thanks again


Klatuu said:
Post back with the all the code as you have it. I tested it and it does
work. There must be some error in copying and pasting the code.

RWilly said:
I'm back to using the original approach you suggested, as each user will have
their own copy of the mdb (front and back end, 30 offices across the state
with no network but the Internet).

On using the code from your last message, I get

run-time error "13"
type mismatch

Debug points to

Set Prop = .CreateProperty("MyProgram", dbText, strProgName)

I've tried specifying an object for CreateProperty, but I don't really know
what I'm doing in this case. I really appreciate your patience, and any help
or suggestions you have.

:

Using the Database Property method is presistent. The original approach I
suggested would really only be useful if you correctly implement your
applcation so that each user has their own copy of the mdb on their computer.

Using a table will work in a multi user environment regardless of how the
deploy the application.

The primary difference is, that once set, the Property can be read without
any other actions.

If you want to have the program presistent througout the application, make
this the Load event of your start up form. Or, if your start up code is not
a form, change the name of the sub, and execute it somewhere in your start up
code. It will ensure the property exists and create it if it does not.

Private Sub Form_Load()
Dim strPrg As String

On Error GoTo Form_Load_Error

strPrg = CurrentDb.Properties("MyProgram")

Form_Load_Exit:

On Error Resume Next

Exit Sub

Form_Load_Error:

If Err.Number = 3270 Then
strPrg = StartProgram(False)
Else
MsgBox "Error " & Err.Number & " (" & Err.DESCRIPTION & _
") in procedure Form_Load of VBA Document Form_frmMasterSubTest"
End If
GoTo Form_Load_Exit

End Sub

Here is the function it calls if the program does not exits:

Private Function StartProgram(blnPropExists) As String
Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

With CurrentDb
If blnPropExists Then
.Properties("MyProgram") = strProgName
Else
Set Prop = .CreateProperty("MyProgram", dbText, strProgName)
.Properties.Append Prop
End If

End With
StartProgram = strProgName
End Function

Now all that is necessary is to set the filter for each form where you want
the filtering to apply. Put this code in the Load Event of the forms:

Me.Filter = "[Program] = '" & Currentdb.Properties("MyProgram") & "'"
Me.FilterOn = True

:

Thanks for the reply. I was hoping you might have an idea on how to make the
filter set on the data entry/editing forms permanent, or sticky, so the
filters remain until they're removed explicitly. It's important enough that
I'm going back to the code you forwarded and seeing if I can use/adapt it.

Regards.


:

That will do just fine, in fact in a multi user environment, you may want to
add the userid to the table. Then in the startup, lookup the userid and if
they already have a program defined, use it.

:

Thanks for your response. Sorry it took me so long to get back. I tried to
implement the code you were kind enough to send. Once I added

currentdb.Properties.Refresh

to the two lines of code in the Immediate Window it ran without errors, but
I couldn’t get the code in the command button to run without errors. I should
have made a note of the exact error.

Right now I’ve created a form that is close to doing what I want it to. I’ve
got an unbound combo box that shows all the local districts (aka local
programs). One I select a local district, I then run the code below from a
command button on the same form.

Private Sub cmdFilterMGSP_Deliv_Click()
Dim strSQL As String

If Me("cboProgFilter") <> "" Then
' Build SQL String.
strSQL = "((tblLocalProg.[ProgID]" _
& " = " & Me("cboProgFilter") & "))" ‘ProgID is a long integer
End If


If strSQL <> "" Then

' Set the Filter property.
Forms![frmMGSP_Deliv].Filter = strSQL
Forms![frmMGSP_Deliv].FilterOn = True
End If

End Sub

Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenForm "frmMGSP_Deliv"
End Sub

I do have to open frmMGSP_Deliv, which seems clumsy, but the filter on
frmMGSP_Deliv is set. However, it doesn’t stay set when it’s opened the next
time. I’ve commented out the code you sent in your last message, so that
shouldn’t be a problem.

Any suggestions are appreciated. Thanks.


:

Getting pretty advanced here, aren't we :)

Not that hard, really. All you need to do is create a database property
that you can read each time you need to open the form and load it's value in
the filter. You may also want a button that allows the user to change the
value of the property if they need to change programs.

The first thing you will need to do is create the property. The quick and
easy way is to do it in the immediate window of the the VBA editor. Here are
the two lines of code to type in:

set prop = currentdb.CreateProperty("MyProgram",dbtext,"New")
currentdb.Properties.Append prop

You can change the name of the property by replacing MyProgram with whatever
you want to call it. I use the value New because we will want that later.

Now, just change your code like this:

strDocName = "frmMGSP_Deliv"
strFilter = CurrentDb.Properties("MyProgram")
If strFilter = "New" Then
currentdb.Properties("MyProgram") = inputbox("Enter Program Name")
strFilter = CurrentDb.Properties("MyProgram")
End If
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

If you want the user to be able to change the program, provide a command
button and in the click event:

Dim strNewProgram

strNewProgram = inputbox("Current Program Is " &
Currentdb.Properties("myprogram") & vbnewline & "Change to")

If Len(strNewProgram) > 0 Then
Currentdb.Properties("MyProgram") = strNewProgram
MsgBox "Program Changed to " & strNewProgram
Else
MsgBox "Change Canceled"
End If


:

Thanks for your help. I can now open the form using a constant, i.e.,

strDocName = "frmMGSP_Deliv"
strFilter = "1"
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

This occurs through a command button on my startup form. Now I’d like to
able to have the users click on this command button, or another one, and have
them choose their own program as the filter to the form. Ideally they would
only have to do this one time, when they first start using the database-that
is, the form would open with the same filter already set every day, so they
don't have to choose their own program every time they use the database.

What do you think of using a command button from the starup form to call a
pop-up form with an unbound combo box that would get their selection, and
then use it to set the form filter? I would appreciate any ideas or comments
you have, regarding where to put code and how to handle the variables.

Thanks again.


:

Use the OpenArgs argument of the OpenForm method to pass the filter value to
the form.
strFilter = "The Filter Value you Want"
DoCmd.OpenForm "frmMGSP_Deliv",,,,strFilter

Then use the OpenArgs property of the form to set the filter in the Load
event.

If Not (IsNull) Me.OpenArgs Then
Me.Filter = "[FieldToFilter] = '" & Me.OpenArgs & "'"
Me.FilterOn = True
End If

:

I’m working on a startup form for a database going to 35 remote sites. I’m
trying to create a command button to set or apply a filter to a form
(frmMGSP_Deliv) in the database, and then open the database for entering or
editing data. I would like the users to be able to choose their own program
as the filter. The values are in tblLocalProg–ProgID, ProgName, etc. I would
like the filter to remain on until the users remove it specifically, via
another command button on the startup form, as 99 percent of the time they
will enter/edit data only for their own local program
 
G

Guest

I compiled the code, that is, while the code window was open I selected
Debog..Compile..MGSP_Accomplishments. I didn't get any error messages, though
Debug still points to

Set Prop = .CreateProperty("MyProgram", dbText, strProgName)

The database is in Aceess 2000 file format, though I'm running Access 2002.

Regards

Klatuu said:
This is very wierd. You code is exactly as I sent it. I even copied yours
and replaced mine, and it still works correctly.
There is a Property object established that is in the line
Dim Prop As Propery

Try compiling your code to see if there are any errors.

RWilly said:
Here is all the code from the Load Event and the Function
*********************

Private Sub Form_Load()
Dim strPrg As String

On Error GoTo Form_Load_Error

strPrg = CurrentDb.Properties("MyProgram")

Form_Load_Exit:

On Error Resume Next

Exit Sub

Form_Load_Error:

If Err.Number = 3270 Then
strPrg = StartProgram(False)
Else
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure Form_Load of VBA Document Form_frmMasterSubTest"
End If
GoTo Form_Load_Exit

End Sub
' Here is the function it calls if the program does not exits:

Private Function StartProgram(blnPropExists) As String
Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

With CurrentDb
If blnPropExists Then
.Properties("MyProgram") = strProgName
Else
Set Prop = .CreateProperty("MyProgram", dbText, strProgName)
.Properties.Append Prop
End If
End With

StartProgram = strProgName
End Function

***************************
Thanks again


Klatuu said:
Post back with the all the code as you have it. I tested it and it does
work. There must be some error in copying and pasting the code.

:

I'm back to using the original approach you suggested, as each user will have
their own copy of the mdb (front and back end, 30 offices across the state
with no network but the Internet).

On using the code from your last message, I get

run-time error "13"
type mismatch

Debug points to

Set Prop = .CreateProperty("MyProgram", dbText, strProgName)

I've tried specifying an object for CreateProperty, but I don't really know
what I'm doing in this case. I really appreciate your patience, and any help
or suggestions you have.

:

Using the Database Property method is presistent. The original approach I
suggested would really only be useful if you correctly implement your
applcation so that each user has their own copy of the mdb on their computer.

Using a table will work in a multi user environment regardless of how the
deploy the application.

The primary difference is, that once set, the Property can be read without
any other actions.

If you want to have the program presistent througout the application, make
this the Load event of your start up form. Or, if your start up code is not
a form, change the name of the sub, and execute it somewhere in your start up
code. It will ensure the property exists and create it if it does not.

Private Sub Form_Load()
Dim strPrg As String

On Error GoTo Form_Load_Error

strPrg = CurrentDb.Properties("MyProgram")

Form_Load_Exit:

On Error Resume Next

Exit Sub

Form_Load_Error:

If Err.Number = 3270 Then
strPrg = StartProgram(False)
Else
MsgBox "Error " & Err.Number & " (" & Err.DESCRIPTION & _
") in procedure Form_Load of VBA Document Form_frmMasterSubTest"
End If
GoTo Form_Load_Exit

End Sub

Here is the function it calls if the program does not exits:

Private Function StartProgram(blnPropExists) As String
Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

With CurrentDb
If blnPropExists Then
.Properties("MyProgram") = strProgName
Else
Set Prop = .CreateProperty("MyProgram", dbText, strProgName)
.Properties.Append Prop
End If

End With
StartProgram = strProgName
End Function

Now all that is necessary is to set the filter for each form where you want
the filtering to apply. Put this code in the Load Event of the forms:

Me.Filter = "[Program] = '" & Currentdb.Properties("MyProgram") & "'"
Me.FilterOn = True

:

Thanks for the reply. I was hoping you might have an idea on how to make the
filter set on the data entry/editing forms permanent, or sticky, so the
filters remain until they're removed explicitly. It's important enough that
I'm going back to the code you forwarded and seeing if I can use/adapt it.

Regards.


:

That will do just fine, in fact in a multi user environment, you may want to
add the userid to the table. Then in the startup, lookup the userid and if
they already have a program defined, use it.

:

Thanks for your response. Sorry it took me so long to get back. I tried to
implement the code you were kind enough to send. Once I added

currentdb.Properties.Refresh

to the two lines of code in the Immediate Window it ran without errors, but
I couldn’t get the code in the command button to run without errors. I should
have made a note of the exact error.

Right now I’ve created a form that is close to doing what I want it to. I’ve
got an unbound combo box that shows all the local districts (aka local
programs). One I select a local district, I then run the code below from a
command button on the same form.

Private Sub cmdFilterMGSP_Deliv_Click()
Dim strSQL As String

If Me("cboProgFilter") <> "" Then
' Build SQL String.
strSQL = "((tblLocalProg.[ProgID]" _
& " = " & Me("cboProgFilter") & "))" ‘ProgID is a long integer
End If


If strSQL <> "" Then

' Set the Filter property.
Forms![frmMGSP_Deliv].Filter = strSQL
Forms![frmMGSP_Deliv].FilterOn = True
End If

End Sub

Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenForm "frmMGSP_Deliv"
End Sub

I do have to open frmMGSP_Deliv, which seems clumsy, but the filter on
frmMGSP_Deliv is set. However, it doesn’t stay set when it’s opened the next
time. I’ve commented out the code you sent in your last message, so that
shouldn’t be a problem.

Any suggestions are appreciated. Thanks.


:

Getting pretty advanced here, aren't we :)

Not that hard, really. All you need to do is create a database property
that you can read each time you need to open the form and load it's value in
the filter. You may also want a button that allows the user to change the
value of the property if they need to change programs.

The first thing you will need to do is create the property. The quick and
easy way is to do it in the immediate window of the the VBA editor. Here are
the two lines of code to type in:

set prop = currentdb.CreateProperty("MyProgram",dbtext,"New")
currentdb.Properties.Append prop

You can change the name of the property by replacing MyProgram with whatever
you want to call it. I use the value New because we will want that later.

Now, just change your code like this:

strDocName = "frmMGSP_Deliv"
strFilter = CurrentDb.Properties("MyProgram")
If strFilter = "New" Then
currentdb.Properties("MyProgram") = inputbox("Enter Program Name")
strFilter = CurrentDb.Properties("MyProgram")
End If
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

If you want the user to be able to change the program, provide a command
button and in the click event:

Dim strNewProgram

strNewProgram = inputbox("Current Program Is " &
Currentdb.Properties("myprogram") & vbnewline & "Change to")

If Len(strNewProgram) > 0 Then
Currentdb.Properties("MyProgram") = strNewProgram
MsgBox "Program Changed to " & strNewProgram
Else
MsgBox "Change Canceled"
End If


:

Thanks for your help. I can now open the form using a constant, i.e.,

strDocName = "frmMGSP_Deliv"
strFilter = "1"
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

This occurs through a command button on my startup form. Now I’d like to
able to have the users click on this command button, or another one, and have
them choose their own program as the filter to the form. Ideally they would
only have to do this one time, when they first start using the database-that
is, the form would open with the same filter already set every day, so they
don't have to choose their own program every time they use the database.

What do you think of using a command button from the starup form to call a
pop-up form with an unbound combo box that would get their selection, and
then use it to set the form filter? I would appreciate any ideas or comments
you have, regarding where to put code and how to handle the variables.

Thanks again.


:

Use the OpenArgs argument of the OpenForm method to pass the filter value to
the form.
strFilter = "The Filter Value you Want"
DoCmd.OpenForm "frmMGSP_Deliv",,,,strFilter

Then use the OpenArgs property of the form to set the filter in the Load
event.

If Not (IsNull) Me.OpenArgs Then
Me.Filter = "[FieldToFilter] = '" & Me.OpenArgs & "'"
Me.FilterOn = True
End If

:
 
G

Guest

Then we are about the same, I am on 2003 in 2000 format.
I promise, it runs for me. Even the code you pasted. I deleted mine an
copied yours in in case I missed something and it still works just fine.
Check you Library references in VBA. In the VBA editor, Tools, References.
Make a list of all those that are checked. Let's see if it could be that.
So we will work through some lower level things.
Check the references.
Do a decompile and recompile.
Do some checking for possible corruption.

RWilly said:
I compiled the code, that is, while the code window was open I selected
Debog..Compile..MGSP_Accomplishments. I didn't get any error messages, though
Debug still points to

Set Prop = .CreateProperty("MyProgram", dbText, strProgName)

The database is in Aceess 2000 file format, though I'm running Access 2002.

Regards

Klatuu said:
This is very wierd. You code is exactly as I sent it. I even copied yours
and replaced mine, and it still works correctly.
There is a Property object established that is in the line
Dim Prop As Propery

Try compiling your code to see if there are any errors.

RWilly said:
Here is all the code from the Load Event and the Function
*********************

Private Sub Form_Load()
Dim strPrg As String

On Error GoTo Form_Load_Error

strPrg = CurrentDb.Properties("MyProgram")

Form_Load_Exit:

On Error Resume Next

Exit Sub

Form_Load_Error:

If Err.Number = 3270 Then
strPrg = StartProgram(False)
Else
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure Form_Load of VBA Document Form_frmMasterSubTest"
End If
GoTo Form_Load_Exit

End Sub
' Here is the function it calls if the program does not exits:

Private Function StartProgram(blnPropExists) As String
Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

With CurrentDb
If blnPropExists Then
.Properties("MyProgram") = strProgName
Else
Set Prop = .CreateProperty("MyProgram", dbText, strProgName)
.Properties.Append Prop
End If
End With

StartProgram = strProgName
End Function

***************************
Thanks again


:

Post back with the all the code as you have it. I tested it and it does
work. There must be some error in copying and pasting the code.

:

I'm back to using the original approach you suggested, as each user will have
their own copy of the mdb (front and back end, 30 offices across the state
with no network but the Internet).

On using the code from your last message, I get

run-time error "13"
type mismatch

Debug points to

Set Prop = .CreateProperty("MyProgram", dbText, strProgName)

I've tried specifying an object for CreateProperty, but I don't really know
what I'm doing in this case. I really appreciate your patience, and any help
or suggestions you have.

:

Using the Database Property method is presistent. The original approach I
suggested would really only be useful if you correctly implement your
applcation so that each user has their own copy of the mdb on their computer.

Using a table will work in a multi user environment regardless of how the
deploy the application.

The primary difference is, that once set, the Property can be read without
any other actions.

If you want to have the program presistent througout the application, make
this the Load event of your start up form. Or, if your start up code is not
a form, change the name of the sub, and execute it somewhere in your start up
code. It will ensure the property exists and create it if it does not.

Private Sub Form_Load()
Dim strPrg As String

On Error GoTo Form_Load_Error

strPrg = CurrentDb.Properties("MyProgram")

Form_Load_Exit:

On Error Resume Next

Exit Sub

Form_Load_Error:

If Err.Number = 3270 Then
strPrg = StartProgram(False)
Else
MsgBox "Error " & Err.Number & " (" & Err.DESCRIPTION & _
") in procedure Form_Load of VBA Document Form_frmMasterSubTest"
End If
GoTo Form_Load_Exit

End Sub

Here is the function it calls if the program does not exits:

Private Function StartProgram(blnPropExists) As String
Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

With CurrentDb
If blnPropExists Then
.Properties("MyProgram") = strProgName
Else
Set Prop = .CreateProperty("MyProgram", dbText, strProgName)
.Properties.Append Prop
End If

End With
StartProgram = strProgName
End Function

Now all that is necessary is to set the filter for each form where you want
the filtering to apply. Put this code in the Load Event of the forms:

Me.Filter = "[Program] = '" & Currentdb.Properties("MyProgram") & "'"
Me.FilterOn = True

:

Thanks for the reply. I was hoping you might have an idea on how to make the
filter set on the data entry/editing forms permanent, or sticky, so the
filters remain until they're removed explicitly. It's important enough that
I'm going back to the code you forwarded and seeing if I can use/adapt it.

Regards.


:

That will do just fine, in fact in a multi user environment, you may want to
add the userid to the table. Then in the startup, lookup the userid and if
they already have a program defined, use it.

:

Thanks for your response. Sorry it took me so long to get back. I tried to
implement the code you were kind enough to send. Once I added

currentdb.Properties.Refresh

to the two lines of code in the Immediate Window it ran without errors, but
I couldn’t get the code in the command button to run without errors. I should
have made a note of the exact error.

Right now I’ve created a form that is close to doing what I want it to. I’ve
got an unbound combo box that shows all the local districts (aka local
programs). One I select a local district, I then run the code below from a
command button on the same form.

Private Sub cmdFilterMGSP_Deliv_Click()
Dim strSQL As String

If Me("cboProgFilter") <> "" Then
' Build SQL String.
strSQL = "((tblLocalProg.[ProgID]" _
& " = " & Me("cboProgFilter") & "))" ‘ProgID is a long integer
End If


If strSQL <> "" Then

' Set the Filter property.
Forms![frmMGSP_Deliv].Filter = strSQL
Forms![frmMGSP_Deliv].FilterOn = True
End If

End Sub

Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenForm "frmMGSP_Deliv"
End Sub

I do have to open frmMGSP_Deliv, which seems clumsy, but the filter on
frmMGSP_Deliv is set. However, it doesn’t stay set when it’s opened the next
time. I’ve commented out the code you sent in your last message, so that
shouldn’t be a problem.

Any suggestions are appreciated. Thanks.


:

Getting pretty advanced here, aren't we :)

Not that hard, really. All you need to do is create a database property
that you can read each time you need to open the form and load it's value in
the filter. You may also want a button that allows the user to change the
value of the property if they need to change programs.

The first thing you will need to do is create the property. The quick and
easy way is to do it in the immediate window of the the VBA editor. Here are
the two lines of code to type in:

set prop = currentdb.CreateProperty("MyProgram",dbtext,"New")
currentdb.Properties.Append prop

You can change the name of the property by replacing MyProgram with whatever
you want to call it. I use the value New because we will want that later.

Now, just change your code like this:

strDocName = "frmMGSP_Deliv"
strFilter = CurrentDb.Properties("MyProgram")
If strFilter = "New" Then
currentdb.Properties("MyProgram") = inputbox("Enter Program Name")
strFilter = CurrentDb.Properties("MyProgram")
End If
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

If you want the user to be able to change the program, provide a command
button and in the click event:

Dim strNewProgram

strNewProgram = inputbox("Current Program Is " &
Currentdb.Properties("myprogram") & vbnewline & "Change to")

If Len(strNewProgram) > 0 Then
Currentdb.Properties("MyProgram") = strNewProgram
MsgBox "Program Changed to " & strNewProgram
Else
MsgBox "Change Canceled"
End If


:

Thanks for your help. I can now open the form using a constant, i.e.,

strDocName = "frmMGSP_Deliv"
strFilter = "1"
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

This occurs through a command button on my startup form. Now I’d like to
able to have the users click on this command button, or another one, and have
them choose their own program as the filter to the form. Ideally they would
only have to do this one time, when they first start using the database-that
is, the form would open with the same filter already set every day, so they
don't have to choose their own program every time they use the database.

What do you think of using a command button from the starup form to call a
pop-up form with an unbound combo box that would get their selection, and
then use it to set the form filter? I would appreciate any ideas or comments
you have, regarding where to put code and how to handle the variables.

Thanks again.


:

Use the OpenArgs argument of the OpenForm method to pass the filter value to
the form.
strFilter = "The Filter Value you Want"
 
G

Guest

Here are the references I have checked:
MS Access 2002 SP3

References
VB for Applications
MS Access 10.0 Object Library
MS ActiveX Data Objects 2.1 Library
OLE Automation
MS DAO 3.6 Object Library

I don't know how to decompile the code. I have been compacting/repairing
regularly, and haven't noticied any obvious signs of corruption. I'll look
for a .log file.


Klatuu said:
Then we are about the same, I am on 2003 in 2000 format.
I promise, it runs for me. Even the code you pasted. I deleted mine an
copied yours in in case I missed something and it still works just fine.
Check you Library references in VBA. In the VBA editor, Tools, References.
Make a list of all those that are checked. Let's see if it could be that.
So we will work through some lower level things.
Check the references.
Do a decompile and recompile.
Do some checking for possible corruption.

RWilly said:
I compiled the code, that is, while the code window was open I selected
Debog..Compile..MGSP_Accomplishments. I didn't get any error messages, though
Debug still points to

Set Prop = .CreateProperty("MyProgram", dbText, strProgName)

The database is in Aceess 2000 file format, though I'm running Access 2002.

Regards

Klatuu said:
This is very wierd. You code is exactly as I sent it. I even copied yours
and replaced mine, and it still works correctly.
There is a Property object established that is in the line
Dim Prop As Propery

Try compiling your code to see if there are any errors.

:

Here is all the code from the Load Event and the Function
*********************

Private Sub Form_Load()
Dim strPrg As String

On Error GoTo Form_Load_Error

strPrg = CurrentDb.Properties("MyProgram")

Form_Load_Exit:

On Error Resume Next

Exit Sub

Form_Load_Error:

If Err.Number = 3270 Then
strPrg = StartProgram(False)
Else
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure Form_Load of VBA Document Form_frmMasterSubTest"
End If
GoTo Form_Load_Exit

End Sub
' Here is the function it calls if the program does not exits:

Private Function StartProgram(blnPropExists) As String
Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

With CurrentDb
If blnPropExists Then
.Properties("MyProgram") = strProgName
Else
Set Prop = .CreateProperty("MyProgram", dbText, strProgName)
.Properties.Append Prop
End If
End With

StartProgram = strProgName
End Function

***************************
Thanks again


:

Post back with the all the code as you have it. I tested it and it does
work. There must be some error in copying and pasting the code.

:

I'm back to using the original approach you suggested, as each user will have
their own copy of the mdb (front and back end, 30 offices across the state
with no network but the Internet).

On using the code from your last message, I get

run-time error "13"
type mismatch

Debug points to

Set Prop = .CreateProperty("MyProgram", dbText, strProgName)

I've tried specifying an object for CreateProperty, but I don't really know
what I'm doing in this case. I really appreciate your patience, and any help
or suggestions you have.

:

Using the Database Property method is presistent. The original approach I
suggested would really only be useful if you correctly implement your
applcation so that each user has their own copy of the mdb on their computer.

Using a table will work in a multi user environment regardless of how the
deploy the application.

The primary difference is, that once set, the Property can be read without
any other actions.

If you want to have the program presistent througout the application, make
this the Load event of your start up form. Or, if your start up code is not
a form, change the name of the sub, and execute it somewhere in your start up
code. It will ensure the property exists and create it if it does not.

Private Sub Form_Load()
Dim strPrg As String

On Error GoTo Form_Load_Error

strPrg = CurrentDb.Properties("MyProgram")

Form_Load_Exit:

On Error Resume Next

Exit Sub

Form_Load_Error:

If Err.Number = 3270 Then
strPrg = StartProgram(False)
Else
MsgBox "Error " & Err.Number & " (" & Err.DESCRIPTION & _
") in procedure Form_Load of VBA Document Form_frmMasterSubTest"
End If
GoTo Form_Load_Exit

End Sub

Here is the function it calls if the program does not exits:

Private Function StartProgram(blnPropExists) As String
Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

With CurrentDb
If blnPropExists Then
.Properties("MyProgram") = strProgName
Else
Set Prop = .CreateProperty("MyProgram", dbText, strProgName)
.Properties.Append Prop
End If

End With
StartProgram = strProgName
End Function

Now all that is necessary is to set the filter for each form where you want
the filtering to apply. Put this code in the Load Event of the forms:

Me.Filter = "[Program] = '" & Currentdb.Properties("MyProgram") & "'"
Me.FilterOn = True

:

Thanks for the reply. I was hoping you might have an idea on how to make the
filter set on the data entry/editing forms permanent, or sticky, so the
filters remain until they're removed explicitly. It's important enough that
I'm going back to the code you forwarded and seeing if I can use/adapt it.

Regards.


:

That will do just fine, in fact in a multi user environment, you may want to
add the userid to the table. Then in the startup, lookup the userid and if
they already have a program defined, use it.

:

Thanks for your response. Sorry it took me so long to get back. I tried to
implement the code you were kind enough to send. Once I added

currentdb.Properties.Refresh

to the two lines of code in the Immediate Window it ran without errors, but
I couldn’t get the code in the command button to run without errors. I should
have made a note of the exact error.

Right now I’ve created a form that is close to doing what I want it to. I’ve
got an unbound combo box that shows all the local districts (aka local
programs). One I select a local district, I then run the code below from a
command button on the same form.

Private Sub cmdFilterMGSP_Deliv_Click()
Dim strSQL As String

If Me("cboProgFilter") <> "" Then
' Build SQL String.
strSQL = "((tblLocalProg.[ProgID]" _
& " = " & Me("cboProgFilter") & "))" ‘ProgID is a long integer
End If


If strSQL <> "" Then

' Set the Filter property.
Forms![frmMGSP_Deliv].Filter = strSQL
Forms![frmMGSP_Deliv].FilterOn = True
End If

End Sub

Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenForm "frmMGSP_Deliv"
End Sub

I do have to open frmMGSP_Deliv, which seems clumsy, but the filter on
frmMGSP_Deliv is set. However, it doesn’t stay set when it’s opened the next
time. I’ve commented out the code you sent in your last message, so that
shouldn’t be a problem.

Any suggestions are appreciated. Thanks.


:

Getting pretty advanced here, aren't we :)

Not that hard, really. All you need to do is create a database property
that you can read each time you need to open the form and load it's value in
the filter. You may also want a button that allows the user to change the
value of the property if they need to change programs.

The first thing you will need to do is create the property. The quick and
easy way is to do it in the immediate window of the the VBA editor. Here are
the two lines of code to type in:

set prop = currentdb.CreateProperty("MyProgram",dbtext,"New")
currentdb.Properties.Append prop

You can change the name of the property by replacing MyProgram with whatever
you want to call it. I use the value New because we will want that later.

Now, just change your code like this:

strDocName = "frmMGSP_Deliv"
strFilter = CurrentDb.Properties("MyProgram")
If strFilter = "New" Then
currentdb.Properties("MyProgram") = inputbox("Enter Program Name")
strFilter = CurrentDb.Properties("MyProgram")
End If
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

If you want the user to be able to change the program, provide a command
button and in the click event:

Dim strNewProgram

strNewProgram = inputbox("Current Program Is " &
Currentdb.Properties("myprogram") & vbnewline & "Change to")

If Len(strNewProgram) > 0 Then
Currentdb.Properties("MyProgram") = strNewProgram
MsgBox "Program Changed to " & strNewProgram
Else
MsgBox "Change Canceled"
End If


:

Thanks for your help. I can now open the form using a constant, i.e.,

strDocName = "frmMGSP_Deliv"
strFilter = "1"
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

This occurs through a command button on my startup form. Now I’d like to
able to have the users click on this command button, or another one, and have
them choose their own program as the filter to the form. Ideally they would
only have to do this one time, when they first start using the database-that
is, the form would open with the same filter already set every day, so they
don't have to choose their own program every time they use the database.

What do you think of using a command button from the starup form to call a
 
G

Guest

Here is a link to info on Decompile
http://www.granite.ab.ca/access/decompile.htm

Check this out regarding references
http://support.microsoft.com/default.aspx?scid=kb;en-us;283115

Here is some info on recovering from corruption.
http://allenbrowne.com/ser-47.html


RWilly said:
Here are the references I have checked:
MS Access 2002 SP3

References
VB for Applications
MS Access 10.0 Object Library
MS ActiveX Data Objects 2.1 Library
OLE Automation
MS DAO 3.6 Object Library

I don't know how to decompile the code. I have been compacting/repairing
regularly, and haven't noticied any obvious signs of corruption. I'll look
for a .log file.


Klatuu said:
Then we are about the same, I am on 2003 in 2000 format.
I promise, it runs for me. Even the code you pasted. I deleted mine an
copied yours in in case I missed something and it still works just fine.
Check you Library references in VBA. In the VBA editor, Tools, References.
Make a list of all those that are checked. Let's see if it could be that.
So we will work through some lower level things.
Check the references.
Do a decompile and recompile.
Do some checking for possible corruption.

RWilly said:
I compiled the code, that is, while the code window was open I selected
Debog..Compile..MGSP_Accomplishments. I didn't get any error messages, though
Debug still points to

Set Prop = .CreateProperty("MyProgram", dbText, strProgName)

The database is in Aceess 2000 file format, though I'm running Access 2002.

Regards

:

This is very wierd. You code is exactly as I sent it. I even copied yours
and replaced mine, and it still works correctly.
There is a Property object established that is in the line
Dim Prop As Propery

Try compiling your code to see if there are any errors.

:

Here is all the code from the Load Event and the Function
*********************

Private Sub Form_Load()
Dim strPrg As String

On Error GoTo Form_Load_Error

strPrg = CurrentDb.Properties("MyProgram")

Form_Load_Exit:

On Error Resume Next

Exit Sub

Form_Load_Error:

If Err.Number = 3270 Then
strPrg = StartProgram(False)
Else
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure Form_Load of VBA Document Form_frmMasterSubTest"
End If
GoTo Form_Load_Exit

End Sub
' Here is the function it calls if the program does not exits:

Private Function StartProgram(blnPropExists) As String
Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

With CurrentDb
If blnPropExists Then
.Properties("MyProgram") = strProgName
Else
Set Prop = .CreateProperty("MyProgram", dbText, strProgName)
.Properties.Append Prop
End If
End With

StartProgram = strProgName
End Function

***************************
Thanks again


:

Post back with the all the code as you have it. I tested it and it does
work. There must be some error in copying and pasting the code.

:

I'm back to using the original approach you suggested, as each user will have
their own copy of the mdb (front and back end, 30 offices across the state
with no network but the Internet).

On using the code from your last message, I get

run-time error "13"
type mismatch

Debug points to

Set Prop = .CreateProperty("MyProgram", dbText, strProgName)

I've tried specifying an object for CreateProperty, but I don't really know
what I'm doing in this case. I really appreciate your patience, and any help
or suggestions you have.

:

Using the Database Property method is presistent. The original approach I
suggested would really only be useful if you correctly implement your
applcation so that each user has their own copy of the mdb on their computer.

Using a table will work in a multi user environment regardless of how the
deploy the application.

The primary difference is, that once set, the Property can be read without
any other actions.

If you want to have the program presistent througout the application, make
this the Load event of your start up form. Or, if your start up code is not
a form, change the name of the sub, and execute it somewhere in your start up
code. It will ensure the property exists and create it if it does not.

Private Sub Form_Load()
Dim strPrg As String

On Error GoTo Form_Load_Error

strPrg = CurrentDb.Properties("MyProgram")

Form_Load_Exit:

On Error Resume Next

Exit Sub

Form_Load_Error:

If Err.Number = 3270 Then
strPrg = StartProgram(False)
Else
MsgBox "Error " & Err.Number & " (" & Err.DESCRIPTION & _
") in procedure Form_Load of VBA Document Form_frmMasterSubTest"
End If
GoTo Form_Load_Exit

End Sub

Here is the function it calls if the program does not exits:

Private Function StartProgram(blnPropExists) As String
Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

With CurrentDb
If blnPropExists Then
.Properties("MyProgram") = strProgName
Else
Set Prop = .CreateProperty("MyProgram", dbText, strProgName)
.Properties.Append Prop
End If

End With
StartProgram = strProgName
End Function

Now all that is necessary is to set the filter for each form where you want
the filtering to apply. Put this code in the Load Event of the forms:

Me.Filter = "[Program] = '" & Currentdb.Properties("MyProgram") & "'"
Me.FilterOn = True

:

Thanks for the reply. I was hoping you might have an idea on how to make the
filter set on the data entry/editing forms permanent, or sticky, so the
filters remain until they're removed explicitly. It's important enough that
I'm going back to the code you forwarded and seeing if I can use/adapt it.

Regards.


:

That will do just fine, in fact in a multi user environment, you may want to
add the userid to the table. Then in the startup, lookup the userid and if
they already have a program defined, use it.

:

Thanks for your response. Sorry it took me so long to get back. I tried to
implement the code you were kind enough to send. Once I added

currentdb.Properties.Refresh

to the two lines of code in the Immediate Window it ran without errors, but
I couldn’t get the code in the command button to run without errors. I should
have made a note of the exact error.

Right now I’ve created a form that is close to doing what I want it to. I’ve
got an unbound combo box that shows all the local districts (aka local
programs). One I select a local district, I then run the code below from a
command button on the same form.

Private Sub cmdFilterMGSP_Deliv_Click()
Dim strSQL As String

If Me("cboProgFilter") <> "" Then
' Build SQL String.
strSQL = "((tblLocalProg.[ProgID]" _
& " = " & Me("cboProgFilter") & "))" ‘ProgID is a long integer
End If


If strSQL <> "" Then

' Set the Filter property.
Forms![frmMGSP_Deliv].Filter = strSQL
Forms![frmMGSP_Deliv].FilterOn = True
End If

End Sub

Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenForm "frmMGSP_Deliv"
End Sub

I do have to open frmMGSP_Deliv, which seems clumsy, but the filter on
frmMGSP_Deliv is set. However, it doesn’t stay set when it’s opened the next
time. I’ve commented out the code you sent in your last message, so that
shouldn’t be a problem.

Any suggestions are appreciated. Thanks.


:

Getting pretty advanced here, aren't we :)

Not that hard, really. All you need to do is create a database property
that you can read each time you need to open the form and load it's value in
the filter. You may also want a button that allows the user to change the
value of the property if they need to change programs.

The first thing you will need to do is create the property. The quick and
easy way is to do it in the immediate window of the the VBA editor. Here are
the two lines of code to type in:

set prop = currentdb.CreateProperty("MyProgram",dbtext,"New")
currentdb.Properties.Append prop

You can change the name of the property by replacing MyProgram with whatever
you want to call it. I use the value New because we will want that later.

Now, just change your code like this:

strDocName = "frmMGSP_Deliv"
strFilter = CurrentDb.Properties("MyProgram")
If strFilter = "New" Then
currentdb.Properties("MyProgram") = inputbox("Enter Program Name")
strFilter = CurrentDb.Properties("MyProgram")
End If
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

If you want the user to be able to change the program, provide a command
button and in the click event:

Dim strNewProgram

strNewProgram = inputbox("Current Program Is " &
Currentdb.Properties("myprogram") & vbnewline & "Change to")

If Len(strNewProgram) > 0 Then
Currentdb.Properties("MyProgram") = strNewProgram
MsgBox "Program Changed to " & strNewProgram
Else
MsgBox "Change Canceled"
End If
 
G

Guest

It seems to be working now. I changed some of the code. It looks like the
“Prop†variable was causing the problem for me, or perhaps the revised syntax
addressed whatever the problem was. The code is below

Private Function StartProgram(blnPropExists) As String
' Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

' With CurrentDb don’t know if I needed to take out the With/End With
If blnPropExists Then
CurrentDb.Properties("MyProgram") = strProgName
Else
CurrentDb.Properties.Append
CurrentDb.CreateProperty("MyProgram", dbText, strProgName)

End If
' End With

StartProgram = strProgName
End Function

Using the code below in my forms, they now open up in a filtered state
(ProgID=Long Int, so I removed the ' )

Me.Filter = "[ProgID] = " & CurrentDb.Properties("MyProgram") & ""
Me.FilterOn = True

When I ran
Currentdb.Properties.Delete("MyProgram")

in the Immediate window it deleted the property, and the next time I opened
my startup form I was prompted for the Program ID in the input box.

Many thanks for all your help and code.

If you have some ideas on how to delete the property through a command
button users can use, when they want or need to remove the filter, I would
be very grateful for any suggestions.

Regards

Klatuu said:
Then we are about the same, I am on 2003 in 2000 format.
I promise, it runs for me. Even the code you pasted. I deleted mine an
copied yours in in case I missed something and it still works just fine.
Check you Library references in VBA. In the VBA editor, Tools, References.
Make a list of all those that are checked. Let's see if it could be that.
So we will work through some lower level things.
Check the references.
Do a decompile and recompile.
Do some checking for possible corruption.

RWilly said:
I compiled the code, that is, while the code window was open I selected
Debog..Compile..MGSP_Accomplishments. I didn't get any error messages, though
Debug still points to

Set Prop = .CreateProperty("MyProgram", dbText, strProgName)

The database is in Aceess 2000 file format, though I'm running Access 2002.

Regards

Klatuu said:
This is very wierd. You code is exactly as I sent it. I even copied yours
and replaced mine, and it still works correctly.
There is a Property object established that is in the line
Dim Prop As Propery

Try compiling your code to see if there are any errors.

:

Here is all the code from the Load Event and the Function
*********************

Private Sub Form_Load()
Dim strPrg As String

On Error GoTo Form_Load_Error

strPrg = CurrentDb.Properties("MyProgram")

Form_Load_Exit:

On Error Resume Next

Exit Sub

Form_Load_Error:

If Err.Number = 3270 Then
strPrg = StartProgram(False)
Else
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure Form_Load of VBA Document Form_frmMasterSubTest"
End If
GoTo Form_Load_Exit

End Sub
' Here is the function it calls if the program does not exits:

Private Function StartProgram(blnPropExists) As String
Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

With CurrentDb
If blnPropExists Then
.Properties("MyProgram") = strProgName
Else
Set Prop = .CreateProperty("MyProgram", dbText, strProgName)
.Properties.Append Prop
End If
End With

StartProgram = strProgName
End Function

***************************
Thanks again


:

Post back with the all the code as you have it. I tested it and it does
work. There must be some error in copying and pasting the code.

:

I'm back to using the original approach you suggested, as each user will have
their own copy of the mdb (front and back end, 30 offices across the state
with no network but the Internet).

On using the code from your last message, I get

run-time error "13"
type mismatch

Debug points to

Set Prop = .CreateProperty("MyProgram", dbText, strProgName)

I've tried specifying an object for CreateProperty, but I don't really know
what I'm doing in this case. I really appreciate your patience, and any help
or suggestions you have.

:

Using the Database Property method is presistent. The original approach I
suggested would really only be useful if you correctly implement your
applcation so that each user has their own copy of the mdb on their computer.

Using a table will work in a multi user environment regardless of how the
deploy the application.

The primary difference is, that once set, the Property can be read without
any other actions.

If you want to have the program presistent througout the application, make
this the Load event of your start up form. Or, if your start up code is not
a form, change the name of the sub, and execute it somewhere in your start up
code. It will ensure the property exists and create it if it does not.

Private Sub Form_Load()
Dim strPrg As String

On Error GoTo Form_Load_Error

strPrg = CurrentDb.Properties("MyProgram")

Form_Load_Exit:

On Error Resume Next

Exit Sub

Form_Load_Error:

If Err.Number = 3270 Then
strPrg = StartProgram(False)
Else
MsgBox "Error " & Err.Number & " (" & Err.DESCRIPTION & _
") in procedure Form_Load of VBA Document Form_frmMasterSubTest"
End If
GoTo Form_Load_Exit

End Sub

Here is the function it calls if the program does not exits:

Private Function StartProgram(blnPropExists) As String
Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

With CurrentDb
If blnPropExists Then
.Properties("MyProgram") = strProgName
Else
Set Prop = .CreateProperty("MyProgram", dbText, strProgName)
.Properties.Append Prop
End If

End With
StartProgram = strProgName
End Function

Now all that is necessary is to set the filter for each form where you want
the filtering to apply. Put this code in the Load Event of the forms:

Me.Filter = "[Program] = '" & Currentdb.Properties("MyProgram") & "'"
Me.FilterOn = True

:

Thanks for the reply. I was hoping you might have an idea on how to make the
filter set on the data entry/editing forms permanent, or sticky, so the
filters remain until they're removed explicitly. It's important enough that
I'm going back to the code you forwarded and seeing if I can use/adapt it.

Regards.


:

That will do just fine, in fact in a multi user environment, you may want to
add the userid to the table. Then in the startup, lookup the userid and if
they already have a program defined, use it.

:

Thanks for your response. Sorry it took me so long to get back. I tried to
implement the code you were kind enough to send. Once I added

currentdb.Properties.Refresh

to the two lines of code in the Immediate Window it ran without errors, but
I couldn’t get the code in the command button to run without errors. I should
have made a note of the exact error.

Right now I’ve created a form that is close to doing what I want it to. I’ve
got an unbound combo box that shows all the local districts (aka local
programs). One I select a local district, I then run the code below from a
command button on the same form.

Private Sub cmdFilterMGSP_Deliv_Click()
Dim strSQL As String

If Me("cboProgFilter") <> "" Then
' Build SQL String.
strSQL = "((tblLocalProg.[ProgID]" _
& " = " & Me("cboProgFilter") & "))" ‘ProgID is a long integer
End If


If strSQL <> "" Then

' Set the Filter property.
Forms![frmMGSP_Deliv].Filter = strSQL
Forms![frmMGSP_Deliv].FilterOn = True
End If

End Sub

Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenForm "frmMGSP_Deliv"
End Sub

I do have to open frmMGSP_Deliv, which seems clumsy, but the filter on
frmMGSP_Deliv is set. However, it doesn’t stay set when it’s opened the next
time. I’ve commented out the code you sent in your last message, so that
shouldn’t be a problem.

Any suggestions are appreciated. Thanks.


:

Getting pretty advanced here, aren't we :)

Not that hard, really. All you need to do is create a database property
that you can read each time you need to open the form and load it's value in
the filter. You may also want a button that allows the user to change the
value of the property if they need to change programs.

The first thing you will need to do is create the property. The quick and
easy way is to do it in the immediate window of the the VBA editor. Here are
the two lines of code to type in:

set prop = currentdb.CreateProperty("MyProgram",dbtext,"New")
currentdb.Properties.Append prop

You can change the name of the property by replacing MyProgram with whatever
you want to call it. I use the value New because we will want that later.

Now, just change your code like this:

strDocName = "frmMGSP_Deliv"
strFilter = CurrentDb.Properties("MyProgram")
If strFilter = "New" Then
currentdb.Properties("MyProgram") = inputbox("Enter Program Name")
strFilter = CurrentDb.Properties("MyProgram")
End If
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

If you want the user to be able to change the program, provide a command
button and in the click event:

Dim strNewProgram

strNewProgram = inputbox("Current Program Is " &
Currentdb.Properties("myprogram") & vbnewline & "Change to")

If Len(strNewProgram) > 0 Then
Currentdb.Properties("MyProgram") = strNewProgram
MsgBox "Program Changed to " & strNewProgram
Else
MsgBox "Change Canceled"
End If


:

Thanks for your help. I can now open the form using a constant, i.e.,

strDocName = "frmMGSP_Deliv"
strFilter = "1"
DoCmd.OpenForm strDocName, , , , acFormEdit, , strFilter

This occurs through a command button on my startup form. Now I’d like to
able to have the users click on this command button, or another one, and have
them choose their own program as the filter to the form. Ideally they would
only have to do this one time, when they first start using the database-that
is, the form would open with the same filter already set every day, so they
don't have to choose their own program every time they use the database.

What do you think of using a command button from the starup form to call a
 
G

Guest

Sure, you can eithe change the value or delete the property.
To delete it, use the code
Currentdb.Properties.Delete("MyProgram")
To change the value
Currentdb.Properties("MyProgram") = "SomeValue"

So you could have a command button with code something like this:

Dim strPrg As String

strPrg = InputBox("Enter New Program Code")
CurrentDb.Properties("MyProgram") = strPrg

You could have a change button and a delete button, but is there any point
in deleting the property?

RWilly said:
It seems to be working now. I changed some of the code. It looks like the
“Prop†variable was causing the problem for me, or perhaps the revised syntax
addressed whatever the problem was. The code is below

Private Function StartProgram(blnPropExists) As String
' Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

' With CurrentDb don’t know if I needed to take out the With/End With
If blnPropExists Then
CurrentDb.Properties("MyProgram") = strProgName
Else
CurrentDb.Properties.Append
CurrentDb.CreateProperty("MyProgram", dbText, strProgName)

End If
' End With

StartProgram = strProgName
End Function

Using the code below in my forms, they now open up in a filtered state
(ProgID=Long Int, so I removed the ' )

Me.Filter = "[ProgID] = " & CurrentDb.Properties("MyProgram") & ""
Me.FilterOn = True

When I ran
Currentdb.Properties.Delete("MyProgram")

in the Immediate window it deleted the property, and the next time I opened
my startup form I was prompted for the Program ID in the input box.

Many thanks for all your help and code.

If you have some ideas on how to delete the property through a command
button users can use, when they want or need to remove the filter, I would
be very grateful for any suggestions.

Regards

Klatuu said:
Then we are about the same, I am on 2003 in 2000 format.
I promise, it runs for me. Even the code you pasted. I deleted mine an
copied yours in in case I missed something and it still works just fine.
Check you Library references in VBA. In the VBA editor, Tools, References.
Make a list of all those that are checked. Let's see if it could be that.
So we will work through some lower level things.
Check the references.
Do a decompile and recompile.
Do some checking for possible corruption.

RWilly said:
I compiled the code, that is, while the code window was open I selected
Debog..Compile..MGSP_Accomplishments. I didn't get any error messages, though
Debug still points to

Set Prop = .CreateProperty("MyProgram", dbText, strProgName)

The database is in Aceess 2000 file format, though I'm running Access 2002.

Regards

:

This is very wierd. You code is exactly as I sent it. I even copied yours
and replaced mine, and it still works correctly.
There is a Property object established that is in the line
Dim Prop As Propery

Try compiling your code to see if there are any errors.

:

Here is all the code from the Load Event and the Function
*********************

Private Sub Form_Load()
Dim strPrg As String

On Error GoTo Form_Load_Error

strPrg = CurrentDb.Properties("MyProgram")

Form_Load_Exit:

On Error Resume Next

Exit Sub

Form_Load_Error:

If Err.Number = 3270 Then
strPrg = StartProgram(False)
Else
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure Form_Load of VBA Document Form_frmMasterSubTest"
End If
GoTo Form_Load_Exit

End Sub
' Here is the function it calls if the program does not exits:

Private Function StartProgram(blnPropExists) As String
Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

With CurrentDb
If blnPropExists Then
.Properties("MyProgram") = strProgName
Else
Set Prop = .CreateProperty("MyProgram", dbText, strProgName)
.Properties.Append Prop
End If
End With

StartProgram = strProgName
End Function

***************************
Thanks again


:

Post back with the all the code as you have it. I tested it and it does
work. There must be some error in copying and pasting the code.

:

I'm back to using the original approach you suggested, as each user will have
their own copy of the mdb (front and back end, 30 offices across the state
with no network but the Internet).

On using the code from your last message, I get

run-time error "13"
type mismatch

Debug points to

Set Prop = .CreateProperty("MyProgram", dbText, strProgName)

I've tried specifying an object for CreateProperty, but I don't really know
what I'm doing in this case. I really appreciate your patience, and any help
or suggestions you have.

:

Using the Database Property method is presistent. The original approach I
suggested would really only be useful if you correctly implement your
applcation so that each user has their own copy of the mdb on their computer.

Using a table will work in a multi user environment regardless of how the
deploy the application.

The primary difference is, that once set, the Property can be read without
any other actions.

If you want to have the program presistent througout the application, make
this the Load event of your start up form. Or, if your start up code is not
a form, change the name of the sub, and execute it somewhere in your start up
code. It will ensure the property exists and create it if it does not.

Private Sub Form_Load()
Dim strPrg As String

On Error GoTo Form_Load_Error

strPrg = CurrentDb.Properties("MyProgram")

Form_Load_Exit:

On Error Resume Next

Exit Sub

Form_Load_Error:

If Err.Number = 3270 Then
strPrg = StartProgram(False)
Else
MsgBox "Error " & Err.Number & " (" & Err.DESCRIPTION & _
") in procedure Form_Load of VBA Document Form_frmMasterSubTest"
End If
GoTo Form_Load_Exit

End Sub

Here is the function it calls if the program does not exits:

Private Function StartProgram(blnPropExists) As String
Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

With CurrentDb
If blnPropExists Then
.Properties("MyProgram") = strProgName
Else
Set Prop = .CreateProperty("MyProgram", dbText, strProgName)
.Properties.Append Prop
End If

End With
StartProgram = strProgName
End Function

Now all that is necessary is to set the filter for each form where you want
the filtering to apply. Put this code in the Load Event of the forms:

Me.Filter = "[Program] = '" & Currentdb.Properties("MyProgram") & "'"
Me.FilterOn = True

:

Thanks for the reply. I was hoping you might have an idea on how to make the
filter set on the data entry/editing forms permanent, or sticky, so the
filters remain until they're removed explicitly. It's important enough that
I'm going back to the code you forwarded and seeing if I can use/adapt it.

Regards.


:

That will do just fine, in fact in a multi user environment, you may want to
add the userid to the table. Then in the startup, lookup the userid and if
they already have a program defined, use it.

:

Thanks for your response. Sorry it took me so long to get back. I tried to
implement the code you were kind enough to send. Once I added

currentdb.Properties.Refresh

to the two lines of code in the Immediate Window it ran without errors, but
I couldn’t get the code in the command button to run without errors. I should
have made a note of the exact error.

Right now I’ve created a form that is close to doing what I want it to. I’ve
got an unbound combo box that shows all the local districts (aka local
programs). One I select a local district, I then run the code below from a
command button on the same form.

Private Sub cmdFilterMGSP_Deliv_Click()
Dim strSQL As String

If Me("cboProgFilter") <> "" Then
' Build SQL String.
strSQL = "((tblLocalProg.[ProgID]" _
& " = " & Me("cboProgFilter") & "))" ‘ProgID is a long integer
End If


If strSQL <> "" Then

' Set the Filter property.
Forms![frmMGSP_Deliv].Filter = strSQL
Forms![frmMGSP_Deliv].FilterOn = True
End If

End Sub

Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenForm "frmMGSP_Deliv"
End Sub

I do have to open frmMGSP_Deliv, which seems clumsy, but the filter on
frmMGSP_Deliv is set. However, it doesn’t stay set when it’s opened the next
time. I’ve commented out the code you sent in your last message, so that
shouldn’t be a problem.

Any suggestions are appreciated. Thanks.


:

Getting pretty advanced here, aren't we :)

Not that hard, really. All you need to do is create a database property
that you can read each time you need to open the form and load it's value in
the filter. You may also want a button that allows the user to change the
value of the property if they need to change programs.

The first thing you will need to do is create the property. The quick and
easy way is to do it in the immediate window of the the VBA editor. Here are
the two lines of code to type in:

set prop = currentdb.CreateProperty("MyProgram",dbtext,"New")
currentdb.Properties.Append prop
 
G

Guest

There's probably no reason for the local offices to delete the property. The
change value approach makes more sense. Thanks again.

Klatuu said:
Sure, you can eithe change the value or delete the property.
To delete it, use the code
Currentdb.Properties.Delete("MyProgram")
To change the value
Currentdb.Properties("MyProgram") = "SomeValue"

So you could have a command button with code something like this:

Dim strPrg As String

strPrg = InputBox("Enter New Program Code")
CurrentDb.Properties("MyProgram") = strPrg

You could have a change button and a delete button, but is there any point
in deleting the property?

RWilly said:
It seems to be working now. I changed some of the code. It looks like the
“Prop†variable was causing the problem for me, or perhaps the revised syntax
addressed whatever the problem was. The code is below

Private Function StartProgram(blnPropExists) As String
' Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

' With CurrentDb don’t know if I needed to take out the With/End With
If blnPropExists Then
CurrentDb.Properties("MyProgram") = strProgName
Else
CurrentDb.Properties.Append
CurrentDb.CreateProperty("MyProgram", dbText, strProgName)

End If
' End With

StartProgram = strProgName
End Function

Using the code below in my forms, they now open up in a filtered state
(ProgID=Long Int, so I removed the ' )

Me.Filter = "[ProgID] = " & CurrentDb.Properties("MyProgram") & ""
Me.FilterOn = True

When I ran
Currentdb.Properties.Delete("MyProgram")

in the Immediate window it deleted the property, and the next time I opened
my startup form I was prompted for the Program ID in the input box.

Many thanks for all your help and code.

If you have some ideas on how to delete the property through a command
button users can use, when they want or need to remove the filter, I would
be very grateful for any suggestions.

Regards

Klatuu said:
Then we are about the same, I am on 2003 in 2000 format.
I promise, it runs for me. Even the code you pasted. I deleted mine an
copied yours in in case I missed something and it still works just fine.
Check you Library references in VBA. In the VBA editor, Tools, References.
Make a list of all those that are checked. Let's see if it could be that.
So we will work through some lower level things.
Check the references.
Do a decompile and recompile.
Do some checking for possible corruption.

:

I compiled the code, that is, while the code window was open I selected
Debog..Compile..MGSP_Accomplishments. I didn't get any error messages, though
Debug still points to

Set Prop = .CreateProperty("MyProgram", dbText, strProgName)

The database is in Aceess 2000 file format, though I'm running Access 2002.

Regards

:

This is very wierd. You code is exactly as I sent it. I even copied yours
and replaced mine, and it still works correctly.
There is a Property object established that is in the line
Dim Prop As Propery

Try compiling your code to see if there are any errors.

:

Here is all the code from the Load Event and the Function
*********************

Private Sub Form_Load()
Dim strPrg As String

On Error GoTo Form_Load_Error

strPrg = CurrentDb.Properties("MyProgram")

Form_Load_Exit:

On Error Resume Next

Exit Sub

Form_Load_Error:

If Err.Number = 3270 Then
strPrg = StartProgram(False)
Else
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure Form_Load of VBA Document Form_frmMasterSubTest"
End If
GoTo Form_Load_Exit

End Sub
' Here is the function it calls if the program does not exits:

Private Function StartProgram(blnPropExists) As String
Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

With CurrentDb
If blnPropExists Then
.Properties("MyProgram") = strProgName
Else
Set Prop = .CreateProperty("MyProgram", dbText, strProgName)
.Properties.Append Prop
End If
End With

StartProgram = strProgName
End Function

***************************
Thanks again


:

Post back with the all the code as you have it. I tested it and it does
work. There must be some error in copying and pasting the code.

:

I'm back to using the original approach you suggested, as each user will have
their own copy of the mdb (front and back end, 30 offices across the state
with no network but the Internet).

On using the code from your last message, I get

run-time error "13"
type mismatch

Debug points to

Set Prop = .CreateProperty("MyProgram", dbText, strProgName)

I've tried specifying an object for CreateProperty, but I don't really know
what I'm doing in this case. I really appreciate your patience, and any help
or suggestions you have.

:

Using the Database Property method is presistent. The original approach I
suggested would really only be useful if you correctly implement your
applcation so that each user has their own copy of the mdb on their computer.

Using a table will work in a multi user environment regardless of how the
deploy the application.

The primary difference is, that once set, the Property can be read without
any other actions.

If you want to have the program presistent througout the application, make
this the Load event of your start up form. Or, if your start up code is not
a form, change the name of the sub, and execute it somewhere in your start up
code. It will ensure the property exists and create it if it does not.

Private Sub Form_Load()
Dim strPrg As String

On Error GoTo Form_Load_Error

strPrg = CurrentDb.Properties("MyProgram")

Form_Load_Exit:

On Error Resume Next

Exit Sub

Form_Load_Error:

If Err.Number = 3270 Then
strPrg = StartProgram(False)
Else
MsgBox "Error " & Err.Number & " (" & Err.DESCRIPTION & _
") in procedure Form_Load of VBA Document Form_frmMasterSubTest"
End If
GoTo Form_Load_Exit

End Sub

Here is the function it calls if the program does not exits:

Private Function StartProgram(blnPropExists) As String
Dim Prop As Property
Dim strProgName As String

strProgName = InputBox("Please Enter Program Code")

With CurrentDb
If blnPropExists Then
.Properties("MyProgram") = strProgName
Else
Set Prop = .CreateProperty("MyProgram", dbText, strProgName)
.Properties.Append Prop
End If

End With
StartProgram = strProgName
End Function

Now all that is necessary is to set the filter for each form where you want
the filtering to apply. Put this code in the Load Event of the forms:

Me.Filter = "[Program] = '" & Currentdb.Properties("MyProgram") & "'"
Me.FilterOn = True

:

Thanks for the reply. I was hoping you might have an idea on how to make the
filter set on the data entry/editing forms permanent, or sticky, so the
filters remain until they're removed explicitly. It's important enough that
I'm going back to the code you forwarded and seeing if I can use/adapt it.

Regards.


:

That will do just fine, in fact in a multi user environment, you may want to
add the userid to the table. Then in the startup, lookup the userid and if
they already have a program defined, use it.

:

Thanks for your response. Sorry it took me so long to get back. I tried to
implement the code you were kind enough to send. Once I added

currentdb.Properties.Refresh

to the two lines of code in the Immediate Window it ran without errors, but
I couldn’t get the code in the command button to run without errors. I should
have made a note of the exact error.

Right now I’ve created a form that is close to doing what I want it to. I’ve
got an unbound combo box that shows all the local districts (aka local
programs). One I select a local district, I then run the code below from a
command button on the same form.

Private Sub cmdFilterMGSP_Deliv_Click()
Dim strSQL As String

If Me("cboProgFilter") <> "" Then
' Build SQL String.
strSQL = "((tblLocalProg.[ProgID]" _
& " = " & Me("cboProgFilter") & "))" ‘ProgID is a long integer
End If


If strSQL <> "" Then

' Set the Filter property.
Forms![frmMGSP_Deliv].Filter = strSQL
Forms![frmMGSP_Deliv].FilterOn = True
End If

End Sub

Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenForm "frmMGSP_Deliv"
End Sub

I do have to open frmMGSP_Deliv, which seems clumsy, but the filter on
frmMGSP_Deliv is set. However, it doesn’t stay set when it’s opened the next
time. I’ve commented out the code you sent in your last message, so that
shouldn’t be a problem.

Any suggestions are appreciated. Thanks.
 

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