Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / August 2005

Tip: Looking for answers? Try searching our database.

locking subform

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Katayon - 02 Aug 2005 16:28 GMT
Hi,

I have searched through all previous messages, and can not find this
specific answer.  I think its pretty simple, but I just can't get it right.

I have a form, and the form has a command button to "Save" (i.e. Lock all
fields), and here is the code for it.

____________________________________
Private Sub SaveRecord_Click()
On Error GoTo Err_SaveRecord_Click

   DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

   Me!CMID.Locked = True
   Me!ArchiveDate.Locked = True
   Me!SCR.Locked = True
   Me!Build.Locked = True
   Me!CMID.Locked = True
   Me!ComponentName.Locked = True
   Me!Comments.Locked = True
   Me!Provider.Locked = True
   
Exit_SaveRecord_Click:
   Exit Sub

Err_SaveRecord_Click:
   MsgBox Err.Description
   Resume Exit_SaveRecord_Click
   
End Sub
___________________________

This works fine.  But I can not figure out the code to lock the subfrom
(sbfrmItems) in the same manner as well.

I have tried things like:     Me!sbfrmItems.Form.Locked = True
and I get an error saying "...can't find the field 'sbfrmItems' referred to
in your expression."

Can someone please tell me what is the proper code for locking a subform,
persistant to the way I am locking individual fields (i.e. textboxes,
drop-downs...).

Thanks in advance!
Brian - 02 Aug 2005 17:27 GMT
Refer to the subform just by its name (just like your controls.

sbfrmItems.Locked = True

> Hi,
>
[quoted text clipped - 41 lines]
>
> Thanks in advance!
Katayon - 02 Aug 2005 19:59 GMT
Thanks Brian.  But now I am getting an error:

Compile error:  variable not defined

any thoughts on that?

thanks again,
katayon

> Refer to the subform just by its name (just like your controls.
>
[quoted text clipped - 45 lines]
> >
> > Thanks in advance!
Brian - 02 Aug 2005 22:56 GMT
Two things:

1. What is the name of your subform? Is it sbfrmItems?
2. Post the full sub VBA code again with this reference in it.

> Thanks Brian.  But now I am getting an error:
>
[quoted text clipped - 54 lines]
> > >
> > > Thanks in advance!
Katayon - 03 Aug 2005 16:51 GMT
1. yes, the name is sbfrmItems

2.

Private Sub SaveRecord_Click()
On Error GoTo Err_SaveRecord_Click

   DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

   Me!CMID.Locked = True
   Me!ArchiveDate.Locked = True
   Me!SCR.Locked = True
   Me!Build.Locked = True
   Me!CMID.Locked = True
   Me!ComponentName.Locked = True
   Me!Comments.Locked = True
   Me!Provider.Locked = True
   
   sbfrmItems.Locked = True

Exit_SaveRecord_Click:
   Exit Sub

Err_SaveRecord_Click:
   MsgBox Err.Description
   Resume Exit_SaveRecord_Click
   
End Sub

> Two things:
>
[quoted text clipped - 59 lines]
> > > >
> > > > Thanks in advance!
Brian - 03 Aug 2005 17:20 GMT
Make a backup copy of your form first, and then replace your click sub with
this. After inserting it (but with the module still open, click Debug ->
Compile. This forces it to attempt to compile and will pinpoint any compile
errors immediately. See if it generates any errors, and if so, where. If
there are no errors, try running it. Also, which version of Access are you
using?

Private Sub SaveRecord_Click()
 On Error GoTo Err_SaveRecord_Click
 DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
 CMID.Locked = True
 ArchiveDate.Locked = True
 SCR.Locked = True
 Build.Locked = True
 CMID.Locked = True
 ComponentName.Locked = True
 Comments.Locked = True
 Provider.Locked = True
 sbfrmItems.Locked = True

Exit_SaveRecord_Click:
 Exit Sub

Err_SaveRecord_Click:
   MsgBox Err.Description
   Resume Exit_SaveRecord_Click
End Sub

> 1. yes, the name is sbfrmItems
>
[quoted text clipped - 88 lines]
> > > > >
> > > > > Thanks in advance!
Katayon - 04 Aug 2005 15:23 GMT
Ok.  I inserted and I compiled, and I received the following error:

"Variable not defined" and it was highlighting "sbfrmItems" from the sub
click.

I am using Microsoft Access 2000 (9.0.2720)

> Make a backup copy of your form first, and then replace your click sub with
> this. After inserting it (but with the module still open, click Debug ->
[quoted text clipped - 116 lines]
> > > > > >
> > > > > > Thanks in advance!
Brian - 04 Aug 2005 17:42 GMT
Access does not recognize "sbfrmItems" as a valid object (i.e. subform) on
your form and therefore thinks it is an undeclared variable. Check & recheck
the spelling. Try this:

Go to design view of your form.
Right-click on the upper right-hand corner of the subform.
Click Properties.
Click the "Other" tab.
Copy the subform name & paste it here:

I just want to make sure it is exactly the same. I am not aware of any
alternative way to refer to the subform. I just posted this question in the
same forum. Give it a couple of hours, and search this forum for "Subform
reference". If the spelling is indeed exact, maybe someone else knows some
trick that is needed to get the correct reference. I am using Access 2003,
and perhaps something was different in Access 2000.

> Ok.  I inserted and I compiled, and I received the following error:
>
[quoted text clipped - 123 lines]
> > > > > > >
> > > > > > > Thanks in advance!
Katayon - 04 Aug 2005 18:45 GMT
well I checked the properties>other>name of the subform on the Form and it
turns out the name there was 'items subform', even though the actual name of
the subform itself is 'sbfrmItems'.  I don't know how that could be possible,
since the Form showed the subform correctly using the wrong name?  Anyway, I
changed the properties>other>name to 'sbfrmItems' and that solved the issue
using Me.sbfrmItems.Locked = True.

Thanks again a million for your help!

Quick question since you said you are using 2003, would it be better to
migrate this 2000 db to 2003?

> Access does not recognize "sbfrmItems" as a valid object (i.e. subform) on
> your form and therefore thinks it is an undeclared variable. Check & recheck
[quoted text clipped - 140 lines]
> > > > > > > >
> > > > > > > > Thanks in advance!
Brian - 04 Aug 2005 18:56 GMT
I don't think there is any pressing reason to migrate. I upgraded only
because I needed to get the developer tools (for distributing the runtime)
and thought I might as well get to the 2003 version so that I wouldn't have
to upgrade for a while. There were also some quirks (i.e. bugs) with the SP3
release for Access 2002 (which is what I had before), and I did not want to
go back to 2000.

> well I checked the properties>other>name of the subform on the Form and it
> turns out the name there was 'items subform', even though the actual name of
[quoted text clipped - 152 lines]
> > > > > > > > >
> > > > > > > > > Thanks in advance!
Katayon - 04 Aug 2005 19:15 GMT
Ok cool.  Thanks again for all your help!

> I don't think there is any pressing reason to migrate. I upgraded only
> because I needed to get the developer tools (for distributing the runtime)
[quoted text clipped - 159 lines]
> > > > > > > > > >
> > > > > > > > > > Thanks in advance!
Brian - 04 Aug 2005 19:13 GMT
The name of the subform as it exists on the form is completely independent of
the name of the subform as you open/edit it directly as a form itself.

There are two properties of the subform that relate to the name:

Data -> SourceObject: the name of the true subform
Other -> Name: the reference to the subform as it exists on the main form

When going through the subform wizard that pops up when you add a subform to
your form:

If you use an existing form (i.e. create the subform alone, then add it to
the main form), it retains the name of the form as both the source objectg
and the form name. If, on the other hand, you build the subform from a table
in the wizard, it names it like this:

"<Table1> name subform"

Let me guess: your table is named "Items"...

> well I checked the properties>other>name of the subform on the Form and it
> turns out the name there was 'items subform', even though the actual name of
[quoted text clipped - 152 lines]
> > > > > > > > >
> > > > > > > > > Thanks in advance!
Brian - 04 Aug 2005 18:16 GMT
I got an answer back on my other post. If the spelling was not thie issue,
try this format:

Me.sbfrmItems.Locked = True

Just "Me" with the dot (.) instead of the exclamation mark(!)

> Ok.  I inserted and I compiled, and I received the following error:
>
[quoted text clipped - 123 lines]
> > > > > > >
> > > > > > > Thanks in advance!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.