Clear contents of Sub form

  • Thread starter cableguy47905 via AccessMonster.com
  • Start date
C

cableguy47905 via AccessMonster.com

I have looked at a previous thread and tried it's suggestion, but it didn't
work.

It was:

To ensure that's nothing selected in a combo box, you need to set it to
Null, not ""

To refer to a control on a subform from the parent form, you need to use:

Me!NameOfSubformControlOnParentForm.Form!NameOfControlOnSubform

Depending on how you added the subform to the parent form, the name of the
subform control may be different than the name of the form being used as a
subform.

To refer to a control on a subform from some other form, you use:

Forms!NameOfParentForm!NameOfSubformControlOnParentForm.Form!
NameOfControlOnSubform



I have tried to refer to my Subform control, but it doesn't recognize the
control name. It gives many options, but no control names can go after:

"Me!NameOfSubformControlOnParentForm.Form"

Plus, I have noticed that everyone puts an "!" after Me and other designated
command words, but I can only put a "." It does not recognize the "!"

Is it my version? I am using MS VB 6.3 editor. I am using Access 2003 SP2.

Thanks,

Lee
 
S

Steve

Open your main form in design view and you will see the subform control as a
border around where your subform is at. Click on the border to select it.
Open Properties and go to the Other tab. Look at and remember the name you
see in the Name property. Let's say the name is SFrmCableGuy.

Open your subform in design view. Select the control you want to refer to.
As above open Properties and get the name. Let's say the name is
CustomerName.

Go to your code. Where you see the line:
Me!NameOfSubformControlOnParentForm.Form!NameOfControlOnSubform
1. put in SFrmCableGuy for NameOfSubformControlOnParentForm.
2. put in CustomerName for NameOfControlOnSubform

Now try your code!

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
[email protected]
 
C

cableguy47905 via AccessMonster.com

The combobox is actually the very first field that is entered on the main
form. There is a way for the subform to update after each field is updated,
right?

Thanks,
Lee
Open your main form in design view and you will see the subform control as a
border around where your subform is at. Click on the border to select it.
Open Properties and go to the Other tab. Look at and remember the name you
see in the Name property. Let's say the name is SFrmCableGuy.

Open your subform in design view. Select the control you want to refer to.
As above open Properties and get the name. Let's say the name is
CustomerName.

Go to your code. Where you see the line:
Me!NameOfSubformControlOnParentForm.Form!NameOfControlOnSubform
1. put in SFrmCableGuy for NameOfSubformControlOnParentForm.
2. put in CustomerName for NameOfControlOnSubform

Now try your code!

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
[email protected]
I have looked at a previous thread and tried it's suggestion, but it didn't
work.
[quoted text clipped - 32 lines]
 
C

cableguy47905 via AccessMonster.com

Sorry, that reply was going to another thread about updating the subform.

As far as this thread goes, I can get the subform name in there, but I can't
refer to any field that is on it. It only recognizes the subform, but not
anything after it.

The combobox is actually the very first field that is entered on the main
form. There is a way for the subform to update after each field is updated,
right?

Thanks,
Lee
Open your main form in design view and you will see the subform control as a
border around where your subform is at. Click on the border to select it.
[quoted text clipped - 22 lines]
 
S

Steve

It's NOT the sybform name you need. You need the name of the subform
control. Look at the first paragraph in my original response.

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
[email protected]





cableguy47905 via AccessMonster.com said:
Sorry, that reply was going to another thread about updating the subform.

As far as this thread goes, I can get the subform name in there, but I
can't
refer to any field that is on it. It only recognizes the subform, but not
anything after it.

The combobox is actually the very first field that is entered on the main
form. There is a way for the subform to update after each field is
updated,
right?

Thanks,
Lee
Open your main form in design view and you will see the subform control
as a
border around where your subform is at. Click on the border to select it.
[quoted text clipped - 22 lines]
 
C

cableguy47905 via AccessMonster.com

Thanks Steve,

This is my code.

It is suppose to Undo everything on the Main form and when it does, I would
like it to clear the datasheet subform.
The two forms are linked by CompanyID

Private Sub cmdUndo_Click()

Me.cboCompanyName.Value = ""
Me.cboCompanyName.DefaultValue = ""
Me.SFRM_AllContractsperCompany.Form.TxtCompanyName.Value = ""

On Error GoTo Err_cmdUndo_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

Exit_cmdUndo_Click:
Exit Sub

Err_cmdUndo_Click:
MsgBox Err.Description
Resume Exit_cmdUndo_Click

End Sub


It's NOT the sybform name you need. You need the name of the subform
control. Look at the first paragraph in my original response.


It is the control that it will not recognize. When writing the code it will
automatically pop up with the different choices that are available when you
get to that spot, but the control is not available. I can type it in, but it
doesn't seem to do anything.

Thanks,
Lee
 
S

Steve

Lee,

You misunderstand "Undo". Undo only clears the current record on a form and
it will only clear edits or new values before the record is saved. Once the
record is saved, Undo will not clear a record displayed on a form. Edits and
new values on a form are saved in three ways:
1. When the user goes to a different record
2. When the form is closed
3. By code
Two points about a form/subform are important to you:
1. For a new record in the main form, data must be entered in one of the
fields in the main form to be able to create a record in the main form's
recordsource before any data can be entered in the subform. Referential
Integrity will prevent you from doing otherwise.
2. When you go from a field in the main form to a field in the subform, a
record of the data in the main form is saved (See 1. in ways records are
saved).

Using the above info, you need to rethink your logic in what you are trying
to do.

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
[email protected]
 
Top