Form VBA w/A2013

Dick7Access

Dick S
Local time
Today, 01:48
Joined
Jun 9, 2009
Messages
4,325
I have a Menu form that has 5 cmdbuttons that opens the same main forms but with 5 different filters. I want a label or text box to change to the name of the filter. I am using VBA to open the form. I can’t code a form that’s not open yet. Is there any way to accomplished the above?
 
This is the command button on the sending form:-
where "XXXX" is the filter name
Code:
Private Sub Command0_Click()
Dim strFrmName As String
strFrmName = "frmPopUp"

    DoCmd.OpenForm strFrmName
    
    With Forms(strFrmName)
    .fX ("XXXX")
    End With

End Sub

This is a Public function in the receiving form:-
Code:
Public Function fX(strPassed As String)

    Me.lblFilter.Caption = strPassed

End Function

Where lblFilter is a label that displays the Filter name
 
Or you could:
1. Set it after opening the form:
Code:
docmd.openform ...
Forms!FormName.LabelName.Caption = "filter"
Or
2. Pass it via OpenArgs
 
I tried that VB,

Code:
With Forms(strFrmName)
    lblFilter.Caption = "filter"
    End With

but it didn't work...

Then I see your answer and realised why:-

Code:
With Forms(strFrmName)
    .lblFilter.Caption = "filter"
    End With

I left the damned period off... time for bed me thinks ....
 
I tried that VB,

Code:
With Forms(strFrmName)
    lblFilter.Caption = "filter"
    End With
but it didn't work...

Then I see your answer and realised why:-

Code:
With Forms(strFrmName)
    .lblFilter.Caption = "filter"
    End With
I left the damned period off... time for bed me thinks ....

My aunt missed a period when i was a kid and the whole family went crazy, and we didn't even have a computer. <G>
 
Yes... Periods can cause all sorts of problems. I prefer "Full Stop" myself, and really, that's a better description if you think about it.
 
Yes... Periods can cause all sorts of problems. I prefer "Full Stop" myself, and really, that's a better description if you think about it.

I have a bigger problem right now. I am in MS and there are at least 5 buffets within 10 miles. Decisions, decisions, decisions.
 
So do I. I think Americans prefer period.

Dick7Access, what happened when you missed your period? :p
 
Or you could:
1. Set it after opening the form:
Code:
docmd.openform ...
Forms!FormName.LabelName.Caption = "filter"
Or
2. Pass it via OpenArgs


Forms!FormName.LabelName.Caption = "filter"
how would the form know what filter cmd I had selected?

Or
2. Pass it via OpenArgs
[/QUOTE]
I will have to look up my notes on "OpnArgus" It has been years since I used it.
 
I thought that you're opening another form, is that not the case?

If you want to apply a filter on the same form where the command buttons are located, you don't need to close and reopen the form.

OpenArgs is one of the parameters in OpenForm.
 
I thought that you're opening another form, is that not the case?

If you want to apply a filter on the same form where the command buttons are located, you don't need to close and reopen the form.

OpenArgs is one of the parameters in OpenForm.

Right, but my menu form has 5 cmd, and nothing else, no data. Each cmd opens the same main form which has the data, but filters it according to the cmd. I have an older version of this db where I did put all the cmd's on the main form and was able to change the lbl without any problem. I am changing it around because I didn't like all the clutter on the main form, plus practicing VBA. I haven't been able to try anything since you guys posted, as I am having to break down the db by states to send it via email to a person in AZ.
 
Ok, you have a menu form and a main form... that was my original thinking. So yes, for you, it's easier to re-open the form.

In order to grab the filter it all depends on how the filter is being passed?
 
UG
This is what is on cmd button on the menu form that opens main data form called “frmChurchesAllDick” filtered by only supporting churches

Code:
  Private Sub cmdSupportingCh_Click()                                   
  Dim strFrmName As String
  strFrmName = "frmChurchesAllDick"
      DoCmd.OpenForm strFrmName    
      With Forms(strFrmName)
      .fX ("Support")
      End With
  End Sub
This is what is on the vba of form “frmChurchesAllDick”
Code:
  Public Function fX(strPassed As String)
      Me.lblFilter.Caption = strPassed
  End Function
This is Where it hangs up

Code:
  With Forms(strFrmName)
      .fX ("Support")
      End With
What do I have wrong?
 
What happens if you comment out the line:-

'fX("Support")
 
Is lblFilter a label? It could be a textbox, which don't have a caption property.
 
Ah, you have put the public function inside a private function, therefore it is not visible to the calling procedure. Make it a separate procedure within your forms module and I suspect it will work.
 

Users who are viewing this thread

Back
Top Bottom