No edits on subform

  • Thread starter Thread starter JIM
  • Start date Start date
J

JIM

I tried this code, found in discussion group, on the OnLoad event of my
subform and I get message "No Parent". The desired result is that subform
does not allow edits. What am I missing? Am using Access 2000.
Thanks, jim

Dim mStr As String
On Error Resume Next
mStr = Me.Parent.frmWorkOrders
If Err.Number > 0 Then
MsgBox "no parent"
me.AllowEdits = true
Else
MsgBox "has parent"
me.AllowEdits = false
End If
 
Jim,
swap the true and false like this:

MsgBox "no parent"
me.AllowEdits = false
Else
MsgBox "has parent"
me.AllowEdits = true

Jeanette Cunningham
 
Thanks Jeanette for your help. This is what I currently have:

Private Sub Form_Load()
Dim mStr As String
On Error Resume Next
mStr = Me.Parent.ZClientBuildings
If Err.Number > 0 Then
Me.AllowEdits = False
Else
MsgBox "No Parent"
Me.AllowEdits = True
End If
End Sub
and it is working well. The other problem is that I need to edit at other
times when subform is connected to another main form. Can I put the whole
subroutine in an if statement based on what form the subform is on?
Thanks, JIM -sorry for late response I'm the only programmer here and also
have lots of other responsibilities.
 
Jim,
here is the way that I like to test a subform is to see if it is loaded as a
form or not.
Assuming A2000 or later, this code will tell you if it is a subform or not.

Private Sub Form_Load()
If CurrentProject.AllForms("YourSubformName").IsLoaded Then
MsgBox "not a subform"
Else
MsgBox "is a subform"
End If
End Sub


Putting the above code together with your code we get:

Private Sub Form_Load()
If CurrentProject.AllForms("YourSubformName").IsLoaded Then
'not a subform
Me.AllowEdits = True
Else
'a subform
If Parent.Name = "ZClientBuildings" Then
Me.AllowEdits = False
ElseIf Parent.Name = "YourOtherFormName" Then
Me.AllowEdits = True
Else
End If
End If
End Sub

Note: make sure you include error handling in the sub.
The above works with A2003 running as A2000 format, not tested with earlier
versions or A2007

Jeanette Cunningham
 
Thanks Jeanette, here's is what I'm using and it's working perfect:

Private Sub Form_Load()
If CurrentProject.AllForms("ZClientBuildings").IsLoaded Or Parent.Name =
"frmWorkOrders" Then
Me.AllowEdits = False 'not a
subform or subform of frmWorkOrders
Me.AllowAdditions = False
Else
If Parent.Name = "frmCustomers" Then 'subform of
frmCustomers
Me.AllowEdits = True
Me.AllowAdditions = True
End If
End If
End Sub
Errors are not handled because I handled all possibilities - see anything
wrong? Thanks again.
Jeannette I M - the real way to spell it : ) just kidding!
 
Glad you got it working, I always like to add an error handler.

Jeanette Cunningham
 

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

Back
Top