Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing ANYTHING about a subform in a VB sub

Status
Not open for further replies.

BadRabbit

Programmer
Nov 14, 2002
28
GB
Hi,

I have a simple form that contains a sub-form. I have a button "delete" that will reference a VB sub, which will perform checks and then, if appropriate, delete the relevant record, be it from the main form or the subform.

The "delete" sub needs therefore to know whether focus is in the subform or the main form. How can this be done? I've tried ActiveForm, which returns only the name of the main form, and ActiveControl which, somewhat unhelpfully, only retrieves the name of the VB sub. I could put up with only the field name being returned, as they are unique between the tables, but I can't even do this.

The only way I can think of doing it is having two delete buttons, which is pretty naff.

Please note I've only been doing Access a couple of days, so any advice will need to be fairly simple!

Thanks.
 
forms!NameOfMainForm!NameOfControlThatHoldsSubForm.form.PropertyOrMethodOfSubform

or

forms!NameOfMainForm!NameOfControlThatHoldsSubForm.form!ControlOnSubform =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
Thanks for the reply. I tried that, but it just gives me "whatever property" of the subform (e.g. ActiveControl), when actually what I'm trying to do figure out if it's the main form or the subform that has focus. If I'm not in the subform, it will still give the subform's last accessed record. It's very possible I'm doing it wrong however... ;)
 
Well here's the thing...once you click on the delete button, the active form is the form holding the delete button.

Are you trying to make a button that deletes either the record on the main form or the record on the subform depending on where the focus is? If so, I would _strongly_ recommend you reconsider. This is not a standard practice and it is guaranteed to confuse your users. If you want them to be able to delete both types of records, then, yes, I would say you're best off with two delete buttons.

As an aside, it's considered best practice to not actually delete records, but simply have a field that archives records, sothat all your forms and reports filter out the records where that field is set to true. That way you don't risk losing data.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
Right, I get you. Yes, I should have realised that the button will make the focus shift. I'll have two buttons then, as it will make things clearer. I'm used to working with ancient mainframe Oracle databases on text-based screens - GIU interfaces take some getting used to!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top