locking subform

K

Katayon

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!
 
B

Brian

Refer to the subform just by its name (just like your controls.

sbfrmItems.Locked = True
 
K

Katayon

Thanks Brian. But now I am getting an error:

Compile error: variable not defined

any thoughts on that?

thanks again,
katayon
 
B

Brian

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.
 
K

Katayon

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
 
B

Brian

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
 
K

Katayon

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)
 
B

Brian

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.
 
B

Brian

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(!)
 
K

Katayon

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?
 
B

Brian

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.
 
B

Brian

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"...
 
K

Katayon

Ok cool. Thanks again for all your help!

Brian said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top