How to fix "Method or data member not found" on AllowEdits button - vba

I'm trying to make a button to lock/unlock edits and adittions in a form and subform.
In my main form CONSULTAS PEDIDOS, I have two subforms CONSULTAS PRODUCTOS y LOTES. When I click on BLOQUEAR button, I want to turn on/off AllowEdits and AllowAditions properties in CONSULTAS PEDIDOS and CONSULTAS PRODUCTOS depending on the caption text, but I want keep editing and adding records in LOTES subform.
I tried this code:
Private Sub bloquear_Click()
With Me.bloquear
If .Caption = "Unlock" Then
Me.AllowAdditions = True
Me.AllowEdits = True
Me.CONSULTA_PRODUCTOS.AllowAdditions = True
Me.CONSULTA_PRODUCTOS.AllowEdits = True
.Caption = "Lock"
Else
Me.AllowAdditions = False
Me.AllowEdits = False
Me.CONSULTA_PRODUCTOS.AllowAdditions = False
Me.CONSULTA_PRODUCTOS.AllowEdits = False
.Caption = "Unlock"
Me.Refresh
End If
End With
End Sub
I tried the code only with main form CONSULTAS PEDIDOS and it works, but when I added CONSULTA PRODUCTOS clauses, Access reports me The expression On Load you entered as the event property setting produced the following error: Method or data member not found. I don't know what I'm doing wrong. I'm a absolute beginner writing code.
Thanks in advance.

Need to follow subform container control name with reference to Form class because those are properties of form object, not container control.
Me.CONSULTA_PRODUCTOS.Form.AllowAdditions = False
Me.CONSULTA_PRODUCTOS.Form.AllowEdits = False

Related

Is there code that i can use to eliminate a runtime error?

In my database (access 2010) there is a "Main menu" form that opens up an event form sourced by the event table after a search from an unbound textbox. Up until the most recent Windows update on 4/10/19 the code was working perfectly to create a new record in the event form. Now I get run-time error 2427 (You entered an expression that has no value). What change in code should be implemented to remove the error?
The debugger breaks in Private Sub Form Load() of the event form in the first If statement which is referencing a true/false control.
I have tried with no luck 1. changing the values to (True/False), 2. adding Me. to the beginning of the if statement, 3. removing the if statements from the form load altogether and setting focus to another control on the form and 4. adding a form current event with the code that was previously in the form load event.
This code closes the "Main Menu" form and opens the events form in add mode.
Private Sub cmdAddEvent_Click()
cmdAddEvent.SetFocus
cboEvent.Value = ""
blnAddEvent = True
On Error GoTo Err_cmdAddEvent_Click
DoCmd.Close
' wipe out event variables when finding or adding another event
strSaveYearCode = "": strSaveProjectCode = "": strSaveActivityCode = "":strSaveProposalCode = ""
g_strEventYear = "": g_strEventProject = "": g_strEventActivity = "": g_strEventProposal = ""
' end of wipe-out
DoCmd.OpenForm "frmEvents", , , , acFormAdd
'DoCmd.GoToRecord , , acNewRec
Exit_cmdAddEvent_Click:
Exit Sub
Err_cmdAddEvent_Click:
MsgBox Err.Description
blnAddEvent = False
Resume Exit_cmdAddEvent_Click
End Sub
This is the code in from the events form that the debugger breaks at before the run-time error appears.
Private Sub Form_Load()
If proContentApprove = -1 Then ---This line
proDescription.Locked = True
proAudience1.Locked = True
Else
If proContentApprove = 0 Then
proDescription.Locked = False
proAudience1.Locked = False
End If
End If
When an record is already in the source table the event form opens without incident. I expect the events form to open as it normally does when trying to add a new record as well.

ContentControlOnEnter event not triggered

I've created a Word VBA app that shows and hides document sections based on checkbox selections.
The sections are bookmarked, and their font is set to hiddden.
The VBA code below works as intended most of the time, but if the user selects and then immediately deselects a given checkbox, without first clicking elsewhere in the document, the hidden section appears but does not disappear.
I'm not sure why the ContentControlOnEnter event is not firing the second time.
Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
If (ContentControl.Title = "Section2CheckBox" And ContentControl.Checked = True) Then
ActiveDocument.Bookmarks("Section2").Range.Font.Hidden = False
End If
If (ContentControl.Title = "Section2CheckBox" And ContentControl.Checked = False) Then
ActiveDocument.Bookmarks("Section2").Range.Font.Hidden = True
End If
With ActiveDocument
.ActiveWindow.View.ShowAll = False 'Hide all formatting marks
.ActiveWindow.View.ShowHiddenText = False 'Do not display hidden text
.Application.Options.PrintHiddenText = False 'Do not print hidden text
End With
End Sub

Toggle Command Button

I was wondering if you guys can help me with this problem. So I want a button that would show/hide a table in ms word. However, I can only get the button to do either show or hide separately with my code. Currently this code will show my table:
Sub Loan1()
'Hides Sections Not Used in Expanded Form
Dim CollapseRange1 As Range
'Set Which Range/Cell to Associate with Button
With ActiveDocument.Tables(3)
Set CollapseRange1 = .Rows(1).Range
CollapseRange1.End = .Rows(25).Range.End
End With
'If button is pressed then Hide/show CollapseRanges
If CommandButton1 = False And CollapseRange1.Font.Hidden = False Then
CollapseRange1.Font.Hidden = True
Else
CollapseRange1.Font.Hidden = False
End If
End Sub
I was hoping to be able to use one button to show and hide my table depending on the state of my table (hidden or unhidden)
Any help would be appreciated!
OH I managed to figure out my questions. Instead of
If CommandButton1 = False And CollapseRange1.Font.Hidden = False Then
I use
If CommandButton1 = False And ActiveDocument.Tables(3).Cell(1, 1).Range.Font.Hidden = False Then
I hoped this helps someone else!

How to create expandable/retractable form MS Access 2013 VBA?

I am creating a data entry form for one of my database tables. For one of the sections, I have the text field with ONLY the caption: "Description 1" showing. If the Description 1 textbox is filled out by the user, I want it to show the Description 2 textbox. If the user fills out the Description 2 textbox, the Description 3 textbox will show up and so on up to 10 Description textboxes. Is there a way to hide the extra text boxes kind of like when you fill out the information while creating a macro? For example when you click Create --> Macro, there is only a dropdown box for you to select an action. If you choose Open Form and hit enter, 6 more text boxes with captions appear.
Is there a way to get that kind of functionality in a form? Also, in the Macro builder, it dynamically rearranges the page for you, can this also be done with the form?
Follow these steps:
Mark the visible property as false
Add OnChange event for each textbox.
Write the VBA code to determine if the next control will be showed or hide. Note, the Me!FormControlItem.Text is accessible only if the control is focused.
There is the 3 functions for each control.
Private Sub text1_Change()
If Not Trim(Me!text1.Text) = "" Then
Me!Text2.Visible = True
Me!Label2.Visible = True
ElseIf Not Trim(Me!Text2) = "" Then
Me!Text2.Visible = True
Me!Label2.Visible = True
Else
Me!Text2.Visible = False
Me!Label2.Visible = False
End If
End Sub
Private Sub Text2_Change()
If Not Trim(Me!Text2.Text) = "" Then
Me!Text3.Visible = True
Me!Label3.Visible = True
ElseIf Not Trim(Me!Text3) = "" Then
Me!Text3.Visible = True
Me!Label3.Visible = True
Else
Me!Text3.Visible = False
Me!Label3.Visible = False
End If
End Sub
Private Sub Text3_Change()
If Not Trim(Me!Text3.Text) = "" Then
Me!Text4.Visible = True
Me!Label4.Visible = True
ElseIf Not Trim(Me!Text4) = "" Then
Me!Text4.Visible = True
Me!Label4.Visible = True
Else
Me!Text4.Visible = False
Me!Label4.Visible = False
End If
End Sub
Enjoy!

How to lock/unlock a subform

I have an access database that has a form that shows information about students, name, class, course etc. On the form I have a subform that shows the grades for the students. I have an edit button with this code:
If Me.AllowEdits = True Then
Me.AllowEdits = False
Me.genderCbo.Locked = True
Me.courseCbo.Locked = True
Me.subfrmGrades.Locked = True
ElseIf Me.AllowEdits = False Then
Me.AllowEdits = True
Me.genderCbo.Locked = False
Me.courseCbo.Locked = False
Me.subfrmGrades.Locked = False
End If
But with this code, whether it is is edit mode or not, I cant edit the grades in the subform. Can someone please come up with a fix? Been searching the internet for a good 30min now and couldn't find anything.
Thanks in advance
You have to reference the Form object within the subform control. To do this use me.subfrmGrades.Form.Allowedits=true instead of just me.subfrmGrades.Allowedits=true.