Adding a new record on another form (1 Viewer)

Chrism2

Registered User.
Local time
Today, 15:18
Joined
Jun 2, 2006
Messages
161
Hi folks, I'm struggling with the exact syntax to do the following.

I have a subform(sfrmContacts) on a form(frmMainDisplay)

I'm using the subform as a placeholder which switches between two subforms that essential display a list of contacts(sfrmContacts) and a detail of a selected contact (popEditContact). Selecting a contact from the list changes the Source form so the user is viewing the second form. All good and well.

I need a button on sfrmContacts that switches the form:

Code:
Forms!frmMainDisplay.ContactPlaceholder.SourceObject = "popEditContact"
(This works)

I then need to unlock some controls:

Code:
For Each ctl In Forms!frmMainDisplay.popEditContact.form
                    If ctl.Tag = "Locked" Then
                        ctl.BorderStyle = 1
                        ctl.Locked = False
                    End If
                Next ctl

I've tried a few permutations of that first line, but I get various errors about it not finding the control.

I then need to, one way or another, move to a new record.

The way I normally do this isn't working either... :mad:

Any pointers?

Thanks folks...
 

MarkK

bit cruncher
Local time
Today, 07:18
Joined
Mar 17, 2004
Messages
8,186
The For...Each...Next loop iterates over a list type like a collection or an array so you want to reference the controls collection ...
Code:
For Each ctrl in Forms!YourForm.Controls
Also if you need to add a record, consider adding it directly to the table. You can write an insert query in the design grid etc...
 

Chrism2

Registered User.
Local time
Today, 15:18
Joined
Jun 2, 2006
Messages
161
The For...Each...Next loop iterates over a list type like a collection or an array so you want to reference the controls collection ...
Code:
For Each ctrl in Forms!YourForm.Controls

Ah, that's what I thought, but when I use

Code:
For Each ctl In Forms!frmMainDisplay.popEditContact.Controls

I'm getting Run Time Error 2465.

I'm not sure what you mean by your second point though, if I'm honest. I use this subform for viewing and editing a contacts details. It's useful to have a button on the first form that calls the second form, unlocks the fields and moves to a new record in the case that a company has no contacts.

I've tried to show on the attached db the element I'm working on; maybe that will clarify.

Thanks for your help, much appreciated!
 

Attachments

  • Sample.zip
    31.2 KB · Views: 90

Chrism2

Registered User.
Local time
Today, 15:18
Joined
Jun 2, 2006
Messages
161
Ah.

Code:
DoCmd.RunCommand acCmdRecordsGoToNew
Form_popEditContact.cmdNew_Click
Forms![frmMainDisplay]![ContactPlaceholder].SetFocus
Forms![frmMainDisplay]![ContactPlaceholder]![Title].SetFocus

Was all I needed to do.

My logic was a little illogical.

Thanks for helping!
 

Users who are viewing this thread

Top Bottom