addressing subform (1 Viewer)

Bladerunner

Registered User.
Local time
Today, 13:38
Joined
Feb 11, 2013
Messages
1,799
does anyone know how to address the subform from within the subform. I can address the mainform from the subform and the subform from the main form and the controls when I am in the form itself but to address the subform from within itself escapes me. I have tried:
Forms.[NavigationSubform].[frmanimalsetup].Form.Requery or
me.navigationsubform.requery

Nothing seems to work and I have found out the hard way, correct addressing is everything?


Thanks for your help in advance.






or
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:38
Joined
Aug 30, 2003
Messages
36,128
Should be the same as addressing from the main form, but from within any object "Me" should work (I'm assuming from VBA).
 

Bladerunner

Registered User.
Local time
Today, 13:38
Joined
Feb 11, 2013
Messages
1,799
At lest it does not give an error but it does not refresh the form with the new data.

Thanks
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:38
Joined
Aug 30, 2003
Messages
36,128
Have you tried

Me.Requery
 

Bladerunner

Registered User.
Local time
Today, 13:38
Joined
Feb 11, 2013
Messages
1,799
Yes, I tried it and do not know if it worked? Was trying to requery a subform after replacing a field with a new number that should have brought up the record and display all its data.

Thanks again.

Blade
 

Bladerunner

Registered User.
Local time
Today, 13:38
Joined
Feb 11, 2013
Messages
1,799
I am changing a combo that is the query value for a tbl. located on a subform!
subF control mainf control
cboanimalID = me.parent.cboanimalID ' This works and transfers the new value to the combo box. Now I need to tell the subform or the combo to requery?

'Me.cboanimal.requery' 'does not work?combo
me.navigationsubform,frmanimalsetup.requery 'does not work? subform
me.frmanimalsetup.requery 'does not work? subform
me.requery 'does not work? subform

I don't think a refresh will do it from what I have read, therefore I have not tried it.

Any suggestions?
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 06:38
Joined
Jan 20, 2009
Messages
12,853
You would have to save the record before the Requery. Otherwise the old value will be loaded again.
 

Bladerunner

Registered User.
Local time
Today, 13:38
Joined
Feb 11, 2013
Messages
1,799
You would have to save the record before the Requery. Otherwise the old value will be loaded again.

Hello Mr. Galaxiom, hope this finds you well this evening. The record showing on the subform should be #1 since initilization of the subform. Your saying it has to be saved regardless of whether anything has changed on the record.? Ok, I 'll try it, thanks for your help.

Blade
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 06:38
Joined
Jan 20, 2009
Messages
12,853
Maybe I misunderstand but this line changes the current record if cboanimalId is bound:

cboanimalID = me.parent.cboanimalID

BTW It should be disambiguated with Me too.
Me.cboanimalID = Me.Parent.cboanimalID

Otherwise VBA goes looking for a variable first.
 

Bladerunner

Registered User.
Local time
Today, 13:38
Joined
Feb 11, 2013
Messages
1,799
Maybe I misunderstand but this line changes the current record if cboanimalId is bound:

cboanimalID = me.parent.cboanimalID

BTW It should be disambiguated with Me too.
Me.cboanimalID = Me.Parent.cboanimalID

Otherwise VBA goes looking for a variable first.


thanks, it did have a (me.cboanimalID),,,however something is wrong, it does not work at all, No it was not your suggestion that did it. I memo'd them out and it still does not work the way it was.. Will get back once I figure this out.. Thanks again.

Blade
 

Bladerunner

Registered User.
Local time
Today, 13:38
Joined
Feb 11, 2013
Messages
1,799
ok, almost got it but have some code problems that are still holding everything up. I have successfully got it to copy the data held in the defaultcboanimalID (mainform) combo to the subform cboanimalID combo.However, It will not requery the table and fill in the subform based upon the copy.

At the Docmd Requery, it gives me an error '2019: there is no field in current record' Although the mainform still has focus (I think) it still should call for a subform requery without actually calling focus to the subform. This way I can continue to pull up data based upon the combo in the mainform. Notice the column(0) RecordID and Column(1) AnimalID. Just need it to pull up the animals data for the one picked in the mainform combo.

The 'DoCmd.GoToControl "me.navigationsubform!cboanimalID",The subform would not recognize it. I was experimenting with it but could never get it to work. Don't think I need it now?.

The 'DoCmd.Save , "Me.NavigationSubform" I tried but it did not make it work even if I added in the 'cboanimalID field name. If data is on a form and has not been changed, does it have to be saved before moving on? I am asking because I do not know.

Private Sub defaultcboAnimalID_AfterUpdate()
'DoCmd.GoToControl "me.navigationsubform!cboanimalID"
'DoCmd.Save , "Me.NavigationSubform"

Me.NavigationSubform!cboanimalID = defaultcboAnimalID.Column(0) 'column (0) RecordID , column(1) AnimlID This part OK

DoCmd.Requery "me.navigationsubform!cboanimalID"
'requery the entire subform. Here is the problem? It will not work with or without the 'cboanimalID'

End Sub

I was hoping someone has some ideas?

Thanks
Blade
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 06:38
Joined
Jan 20, 2009
Messages
12,853
DoCmd.Save is to save the design of the form.

One way to save the data on the form is to change the Dirty Property to False.
 

Bladerunner

Registered User.
Local time
Today, 13:38
Joined
Feb 11, 2013
Messages
1,799
Hi Galaxiom:

something like this?
*********************
If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.RunCommand(acCmdSaveRecord
**************

OK, but why would I have to do that????no laughing, I am thinking here. Maybe I have been looking at this problem from the bottom up instead of from the top down.

In the afterupdate event of the mainforms 'cboanimalID' , would it be better after the above code, to add code calling a simple query to find and display the data on the subform based on the mainform cboanimalID value instead of trying to make it copy the value to the subforms cboanimalID and then find the record?

This way if I am searching singly through the records, no data on the subforms controls would be changed/damaged in between the record selection(s)..Here if the record is needed to be changed, an Edit cmd button could be used and so on.......

Thanks and hope you had a good weekend. Busy here, Christmas and all!

Blade
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 06:38
Joined
Jan 20, 2009
Messages
12,853
DoCmd.RunCommand acCmdSaveRecord is another way to sava the current record.

However I have misunderstood what you were doing. I didn't realise cboAnimalID was an unbound control. It shouldn't have to be saved.

Instead of searching the subform, couldn't you you simply set it up in the usual way with the Master and Child LinkFields properties? Then whatever is selected on the mainform is automatically used to filter the records on the subform.
 

Bladerunner

Registered User.
Local time
Today, 13:38
Joined
Feb 11, 2013
Messages
1,799
I guess I am not too good at explaining what I needed. but the master and child properties does not show up in the properties section of the navigation form/subform or at least I cannot find it. I sent a small version of the DB in forums Form section Navigation subform problem #4. Keep in mind these factors. The type, location and Group only affect specificity of the cboanimalID at the mainlevel. This combo (cboanimalID) is still an unbound column that pulls up animalID from the main tbl (tblanimalsetup0. This tbl is tied to all other tbls in some way by the animalID.

The included subform, is the tblanimalsetup form. WHen I pick an animalID number from the unbound combobox at the main level, the subform 'frmanimalsetup' should pull up the record for this animal. I can then use an Edit button if needed.

hope this makes sense
Blade


I think somewhere I have got lost. Think it is time to start again,.

Thanks
 

Bladerunner

Registered User.
Local time
Today, 13:38
Joined
Feb 11, 2013
Messages
1,799
Galaxiom; to make it a little easier, enter pick 'dogs' (type), 'Deceased' (Group) and 'Ancestory' (location). This will give you something in the combo cboanimalID.

I have been addressing the table problems and have them pretty well fix in the main form here. Although these problems should not affect what I am trying to do. or at least I think it should not?

Blade
 

Bladerunner

Registered User.
Local time
Today, 13:38
Joined
Feb 11, 2013
Messages
1,799
Pardon me, another question: I am trying to use the code to recordselect the animalID .
The navigation form doe not have master/child properties (at least where you can change them.

Using this code. I still get cannot find object. I am wondering if after form-load, the subform is closed (caused by my usig the combo on the mainform. If this is the case, I should be able to use a docmd openform,,,

Me.NavigationSubform.Form.RecordSource = "SELECT * FROM [tblAnimal Setup] WHERE [tblAnimal Setup].AnimalSetupID='" & defaultcboAnimalID.Column(0) & "'"

any thoughts on this direction
 

AccessBlaster

Registered User.
Local time
Today, 13:38
Joined
May 22, 2010
Messages
5,983
Pardon me, another question: I am trying to use the code to recordselect the animalID .
The navigation form doe not have master/child properties (at least where you can change them.
Bingo! you do not have a classic form / subform. You have a main form and a hybrid Access form called "Navigation" from the Access 2010 create menu. You basically have a form embedded within a form, neither forms are related but both forms share the same table.
 

Bladerunner

Registered User.
Local time
Today, 13:38
Joined
Feb 11, 2013
Messages
1,799
Hello AccessBlaster:

Yes, it is a Access 2010 navigtion form with subform tabs. The subform is actually according to everything I have read considered a control. What I have be dealing with could be done easily via a form and subform through a switchboard. Guess I am determined to do it the hard way. almost have it There is a lot of different problems out there with Navigation Form and its subforms and this be one of them that will get solved.

Thanks for your help

Blade
 

AccessBlaster

Registered User.
Local time
Today, 13:38
Joined
May 22, 2010
Messages
5,983
Yes it's a control and you can interact with it. You have added layers of controls and subforms when you only have one table.
 

Users who are viewing this thread

Top Bottom