Getting subforms to manipulate eachother on a navigation form (1 Viewer)

PhoenixofMT

Part-time Access Guru
Local time
Today, 15:05
Joined
Jul 23, 2008
Messages
35
I'm having trouble passing data between subforms on my new navigation form (frmNavigator). Before, I just used OpenArgs and the Split function in the opened form's OnLoad.
I'm trying to keep it simple (haha) by using my existing forms as subforms.

So, I have a subform--frmSCLEdit--that displays information about a program (what it does, who wrote it, other files required to use it, etc.) Part of this form is a (display only) subform that displays information about revisions that have been made to each program. On the edit form I have a button to allow the user to open another form--frmSCLChanges--to record new revision information. Ideally, the name of the program from the edit form will be automatically entered in the correct control in a new record on the revision form. When the revision form is closed, it refreshes the edit form to update its subform.


I've managed to get the DoCmd.BrowseToForm to work, but now I'm having trouble passing the program name. What I've tried so far is along the lines of:


Code:
Dim strDefault As String
  
  strDefault = Me.txtProgName
  
  If HasParent Then
    DoCmd.BrowseTo acBrowseToForm, "frmSCLChanges", "frmNavigator.NavigationSubform", , , acFormAdd
  With [Forms]!frmNavigator!NavigationSubform
      .Form.SetFocus
      .Form.DataEntry = True
      .Form!cmbCTPProgName.SetFocus
      RunCommand acCmdRecordsGoToNew
      .Form!cmbCTPProgName = strDefault
End With
  Else
    DoCmd.OpenForm "frmSCLChanges", acNormal, , , acFormAdd, , Me.Name & ";" & Me.txtProgName & ";" & "False"
  End If

For some reason the acFormAdd in the BrowseTo line doesn't seem to be having an effect. When the user navigates manually to the revision form, they should be able to browse through the records. When they are sent there from the edit form, I want it to be in data entry mode. The stuff in the With block came from another site
but throws errors all over the place.
.Form.SetFocus throws error 2449: "There is an invalid method in an expression."
.Form!cmbCTPProgName.SetFocus gives error 2105: "You can't go to the specified record."
RunCommand acCmdRecordsGoToNew gives error 2046: "The command or action 'RecordsGoToNew' isn't available now."
.Form!cmbCTPProgName = strDefault gives error 2448: "You can't assign a value to this object."

For now I just have the form opening by itself.
Thought I just had:
Invisible text boxes on the navigation form to be place-holders in lieu of the OpenArgs?

Anyone have any ideas?
 

vbaInet

AWF VIP
Local time
Today, 22:05
Joined
Jan 22, 2010
Messages
26,374
I'm guessing that HasParent is a global variable? How do you ensure that you are always setting/resetting the variable appropriately? With OpenArgs you don't have to worry about this.

Anyway, I will go through your problems:

Q: .Form.SetFocus throws error 2449: "There is an invalid method in an expression."
A: .SetFocus - you set focus to the subform control, not the form.

Q: .Form!cmbCTPProgName.SetFocus gives error 2105: "You can't go to the specified record."
A: .Form.cmbCTPProgName.SetFocus - cmbCTPProgname is a control, hence a dot is what to use.

Q: RunCommand acCmdRecordsGoToNew gives error 2046: "The command or action 'RecordsGoToNew' isn't available now."
A: If the subform control hasn't yet gotten focus then it will fail.

Q: .Form!cmbCTPProgName = strDefault gives error 2448: "You can't assign a value to this object."

A: This is a calculated control source. So I believe the Control Source begins with =
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 07:05
Joined
Jan 20, 2009
Messages
12,856
Q: .Form!cmbCTPProgName.SetFocus gives error 2105: "You can't go to the specified record."
A: .Form.cmbCTPProgName.SetFocus - cmbCTPProgname is a control, hence a dot is what to use.

That won't be the case. Objects (such as controls) can be preceded by the Bang (!). With either the Dot or Bang the compiler first looks for a control by the name and if none is found, then a field in the recordset.

The Dot is only essential if the following term is a Property or Method.
 

PhoenixofMT

Part-time Access Guru
Local time
Today, 15:05
Joined
Jul 23, 2008
Messages
35
HasParent is a property that is set at the top of the module.

Code:
Private Property Get HasParent() As Boolean
On Error GoTo handler
  HasParent = TypeName(Me.Parent.Name) = "String"
  Exit Property
handler:
End Property
Yes, OpenArgs would save my bacon, but I'm using a DoCmd.BrowseTo, not DoCmd.OpenForm. If the edit form has no parent it makes very effective use of OpenArgs.
I originally started this project with Access 2000 and I'm trying to keep the original windowed capability because the individual forms will probably be ready to go live with the old switchboard before I can get the navigation form to work.

A: .SetFocus - you set focus to the subform control, not the form.

Thank you. This works now. (Wish I was less dependant on InteliSense.) Unfortunately, the rest of it still refuses to cooperate.
I moved the RunCommand line up to come after the .SetFocus, but it still won't work.
Also, I see now that while the .DataEntry = True works, the form comes up blank except for the header.

Q: .Form!cmbCTPProgName = strDefault gives error 2448: "You can't assign a value to this object."
A: This is a calculated control source. So I believe the Control Source begins with =
This is a combo box, it's the control I'm trying to pass a value to.

I'm thinking I'll just set up an invisible text box on the navigation form to hold passed arguments. Then I can just let the called form change its own properties like with OpenArgs.
 

PhoenixofMT

Part-time Access Guru
Local time
Today, 15:05
Joined
Jul 23, 2008
Messages
35
I think I see a pattern.
I'm having a similar problem on another form I'm trying to use in the navigation form. The form has a subreport in it with some buttons and a textbox for filtering the report.

The code for the filter button was:
Code:
Private Sub cmdFilter_Click()
Dim strFilter As String

  strFilter = Me.txtFilter
  If Nz(Me.txtFilter) <> "" Then
    Me.srpTestedPartsByFixture.Report.Filter = "strFixtureID Like """ & strFilter & "*"""
    Me.srpTestedPartsByFixture.Report.FilterOn = True
    'Me.srpTestedPartsByFixture.Report.Requery
    Me.cmdUnFilter.Visible = True
    Me.cmdUnFilter.SetFocus
    Me.cmdFilter.Visible = False
 End If

End Sub
It would hang up at Me.cmdUnFilter.Visible = True saying the control is closed or doesn't exist.
When I changed it to:
Code:
Private Sub cmdFilter_Click()
Dim strFilter As String

  strFilter = Me.txtFilter
  If Nz(Me.txtFilter) <> "" Then
    Me.cmdUnFilter.Visible = True
    Me.cmdUnFilter.SetFocus
    Me.cmdFilter.Visible = False
    Me.srpTestedPartsByFixture.Report.Filter = "strFixtureID Like """ & strFilter & "*"""
    Me.srpTestedPartsByFixture.Report.FilterOn = True
    'Me.srpTestedPartsByFixture.Report.Requery
  End If

End Sub
it hung up at Me.srpTestedPartsByFixture.Report.FilterOn = True for a similar reason. I thought the subreport might be stealing the focus before the procedure was finished causing 'Me.' to be an invalid reference, but now I've gone and changed it back to the original code so I could post the exact error and it's fixed itself! :eek::confused::mad:
I blame this old PC I'm using.
I'm going to reboot and try again.
 
Last edited:

PhoenixofMT

Part-time Access Guru
Local time
Today, 15:05
Joined
Jul 23, 2008
Messages
35
Well, I think I got it working tolerably. I put an invisible text box called Args on the navigation form and I'm working on getting all the buttons on my forms to check for a parent form and navigate accordingly.
I think I'm going to have to learn to save (more) often and reboot my PC a couple of times a day. Access can really start acting weird after 8 hours or so.
 

vbaInet

AWF VIP
Local time
Today, 22:05
Joined
Jan 22, 2010
Messages
26,374
Also, if you don't Compile often you will get into similar problems.
 

PhoenixofMT

Part-time Access Guru
Local time
Today, 15:05
Joined
Jul 23, 2008
Messages
35
I've gotten in the habit of clicking the compile button before I go back to the form (or whatever) the see what the changes do. It's handy for checking syntax, etc., but I still run into problems.

Anyway, I found a new better way to take care of my value passing problem: TempVars

I just add a block like this:
Code:
  With TempVars
    !CallingForm = Me.Name
    !CalledForm = "frmSCLChanges"
    !NewValue = Me.txtProgram
    !Mode = mdAdd
    !Mandatory = False
  End With
before I open or browse to the form, and the opening form takes care of the rest.:D
 

Users who are viewing this thread

Top Bottom