I've been trying to make a button disappear when a new insert is made and one of the fields is empty, problem is the field is on a subform (data sheet view) and the button on the main form I've been trying the following code with no success.
If Me.Produto = "" Then
[Orçamentos]!Comando33.Visible = False
[Orçamentos]!Comando47.Visible = False
Me.Descrição.Visible = False
End If
Any advice?
Assuming Me is the sub form, and Orçamentos is the main form:
If Me.Produto = "" Then
Me.Parent!Comando33.Visible = False
Me.Parent!Comando47.Visible = False
Me.Descrição.Visible = False
End If
Related
I was wondering if it were possible to have a field shown or active if another previous field is selected.
For example, if I have a Status field and then choose Inactive then I would like another field to show for Inactive Date
Thanks
Let say, you have checkbox for status and textbox to capture date on your form. AfterUpdate event gets triggered when control value changes and you can enable/disable other controls here.
Private Sub chkStatus_AfterUpdate()
If Me.chkStatus Then
Me.txtDate.Enabled = True
Else
Me.txtDate.Enabled = False
End If
End Sub
To enable/disable textbox on dropdown change using VBA
Private Sub cmbStatus_Change()
If Nz(Me.cmbStatus, "") = "Active" Then
Me.txtDate.Enabled = True
ElseIf Nz(Me.cmbStatus, "") = "InActive" Then
Me.txtDate.Enabled = False
End If
End Sub
Using Macro builder - without VBA
I have a one-to-one relationship between an SLD table and an ORDER table. The SLD table is the main form, ORDER table is the subform. The main form's table has more records than the subform table. Master and child links are set. I have decompiled and have done compact and repair. I suspect my application is malfunctioning. In that case it is not the first time (I have fixed it before). Nothing seems to be working this time. I have also imported into a new database.
On form-load both forms and fields are working fine. I continue to the next records using a ['NEXT'] button and reach the end of the sub-forms records therefore having blanks fields. I try to navigate to the previous records (also using a button) but the subform does not move/navigate. Nothing happens to the subform.
It seems like it has gotten worse because first it was navigating but it was not obeying code saying when text box is filled disable checkbox and vise versa.
From the sounds of it the issue is in your Next button rather than it being a subform issue. As you stated in the comments the default navigation allows the form to work as expected.
Is this logic out in your Previous button OnClick Event? Also to be safe i would add in the OR statement in the below code to be extra sure that its catching nulls or blanks
If (IsNull(Forms!Order!OrderSubform.Form!txtDate_Of_Order.Value)) OR Forms!Order!OrderSubform.Form!txtDate_Of_Order.Value <> "" Then
Forms!Order!OrderSubform.Form!txtDate_Of_Order.Enabled = False
Forms!Order!OrderSubform.Form!chkbxOrder_Cancelled.Enabled = True
Forms!Order!OrderSubform.Form!chkbxOrder_Cancelled.Value = True
Else
Forms!Order!OrderSubform.Form!txtDate_Of_Order.Enabled = True
Forms!Order!OrderSubform.Form!chkbxOrder_Cancelled.Enabled = False
Forms!Order!OrderSubform.Form!chkbxOrder_Cancelled.Value = False
End If
I found out that the If statement belonged in Form_Current event. I am not experiencing the problem anymore after this code:
Private Sub Form_Current()
If (IsNull(Forms!Order!OrderSubform.Form!txtOrder_Number.Value) Or _
Forms!Order!OrderSubform.Form!txtOrder_Number.Value = "") Then
Forms!Order!OrderSubform.Form!txtDate_Of_Order.Enabled = True
Forms!Order!OrderSubform.Form!chkbxOrder_Cancelled.Enabled = True
ElseIf (IsNull(Forms!Order!OrderSubform.Form!txtDate_Of_Order.Value) Or _
Forms!Order!OrderSubform.Form!txtDate_Of_Order.Value = "") Then
Forms!Order!OrderSubform.Form!txtDate_Of_Order.Enabled = False
Forms!Order!OrderSubform.Form!chkbxOrder_Cancelled.Enabled = True
Forms!Order!OrderSubform.Form!chkbxOrder_Cancelled.Value = True
Else
Forms!Order!OrderSubform.Form!txtDate_Of_Order.Enabled = True
Forms!Order!OrderSubform.Form!chkbxOrder_Cancelled.Enabled = False
Forms!Order!OrderSubform.Form!chkbxOrder_Cancelled.Value = False
End If
End Sub
I was hoping to use one form that has 3 layouts, but change the data source as the form loads. Here is the code that is called during OnLoad
Private Sub ShowInputLog(iLogType As Integer)
'Determines the Log Type Layout
'For data entry
Select Case iLogType
Case 1 '"MIPR"
Me.Caption = "MIPR"
Me.RecordSource = "tbl_MIPR"
Me.TabCodes.Pages(0).Visible = True
Me.TabCodes.Pages(0).Enabled = True
Me.cmbPR_NUM.SetFocus
Me.TabCodes.Pages(1).Visible = False
Me.TabCodes.Pages(2).Visible = False
Case 2 '"SPSPR"
Me.RecordSource = "tbl_SPSPR"
Me.Caption = "SPSPR"
Me.TabCodes.Pages(0).Visible = False
Me.TabCodes.Pages(1).Visible = True
Me.cmbPR_Contr.SetFocus
Me.TabCodes.Pages(2).Visible = False
Case 3 '"WBS"
Me.RecordSource = "tbl_WBS"
Me.Caption = "WBS"
Me.TabCodes.Pages(0).Visible = False
Me.TabCodes.Pages(1).Visible = False
Me.TabCodes.Pages(2).Visible = True
Me.cmbWBS_Num.SetFocus
End Select
End Sub
Will this work? I was hoping to see the recordsource property with my table defined, but it remains blank.
Yes, this should work, but all tables should have displayed columns with the same names. If you have different names, create few subforms and change subform's SourceObject property on main form depending on iLogType
Yes, this should work, but all tables should have displayed columns with the same names. If you have different names, create a query on each table, having identical field names, expected by the form.
Such code runs on one of my Apps for 9 different queries.
Hi I have a form which contains a sub-report in it. Subreport contains month-wise list with buttons which export data from access db to excel. I am trying to hide the buttons in the report if the month field in the access db are empty. I have tried the code below but the button still appears in the report. The button is getting hidden when i focus on the report but not on loading. Any suggestions?
Private Sub Report_Current()
If IsNull(Me!RcvdMnth) Then
Me.btnExport.Visible = False
Else
Me!btnExport.Visible = True
End If
End Sub
try using the same code on the on load event.
Private Sub Report_Load()
If IsNull(Me!RcvdMnth) Then
Me.btnExport.Visible = False
Else
Me!btnExport.Visible = True
End If
End Sub
Try this:
Private Sub Report_Current()
If IsEmpty(Me!RcvdMnth) Or IsNull(Me!RcvdMnth) Then
Me.btnExport.Visible = False
Else
Me.btnExport.Visible = True
End If
End Sub
I tried to recreate a form and subreport based on your description and it worked for me.
I have a form ("Patient Complications") where users input data to a form using 2 cascading combo boxes ("catcombo" and "speccombo"). The combo boxes pull their values from a table ("Complications"). The table has a field for complication category (for example, infection, bleeding, mechanical). A second field lists specific complications (for example, if the complication category is "bleeding", the specific complication could be "GI" or "other"). The input from the combo boxes are concatenated and put into a text field on the form ("Complication"). That part works fine.
My form has several command buttons, including "edit" and "save" command buttons. Since I don't want users interacting with the "complication" field on the form, I have the field become not visible when the "edit" button is clicked. Instead, the 2 combo boxes become visible and allow users to input data. When "save" is selected, the reverse occurs. The two combo boxes become not visible, and the complication field becomes visible and locked.
Unfortunately, when "edit" is selected, the combo boxes are visible but show up blank (nothing is selected or displayed). I am trying to have the boxes display the inputs that were given to the text field. For example, if the text field displays "Bleeding, Other", I want the catcombo box to display "Bleeding" and the speccombo box display "Other". I have been unable to find anything to this effect. If anyone has any ideas it would be greatly appreciated.
The relevant code is included below. Please let me know if I can provide further clarification.
Private Sub catcombo_AfterUpdate()
Me.speccombo.Requery
End Sub
Private Sub speccombo_OnCurrent()
Dim strsql As String
strsql = "SELECT [Complications]![Specific Complication] FROM tblComplications" & _
"WHERE [Complication Category]=Forms![Patient Complications]![catcombo].value"
End Sub
Private Sub speccombo_AfterUpdate()
Forms![Patient Complications]![Complication] = Me.catcombo.Value & ", " & Me.speccombo.Value
End Sub
Private Sub save_Click()
Me.recordcount.Caption = "Record " & Me.CurrentRecord & " of " & Me.Recordset.recordcount
Me.Patient_Initials.Visible = False
Date_of_Complication.Locked = True
Complication.Visible = True
Complication.Locked = True
comments.Locked = True
catcombo.Visible = False
speccombo.Visible = False
Me.edit.Visible = True
Me.edit.SetFocus
Me.help.Visible = False
Me.save.Visible = False
Me.first.Visible = True
Me.next.Visible = True
Me.previous.Visible = True
Me.last.Visible = True
Me.addnew.Visible = True
Me.close.Visible = True
Me.cancel.Visible = False
End Sub
Private Sub edit_Click()
Me.recordcount.Caption = "Record " & Me.CurrentRecord & " of " & Me.Recordset.recordcount
Me.Patient_Initials.Visible = False
Date_of_Complication.Locked = False
Complication.Visible = False
comments.Locked = False
catcombo.Visible = True
catcombo.Locked = False
catcombo.Enabled = True
speccombo.Visible = True
speccombo.Locked = False
speccombo.Enabled = True
Me.cancel.Visible = True
Me.cancel.SetFocus
Me.edit.Visible = False
Me.help.Visible = True
Me.save.Visible = True
Me.first.Visible = False
Me.next.Visible = False
Me.previous.Visible = False
Me.last.Visible = False
Me.addnew.Visible = False
Me.close.Visible = False
End Sub
I figured it out. I added a field to the "Complications" table called "Input". This field contains the concatenated values that were put into the patient record (in the example above, the input field would be "Bleeding, Other"). The values in the Input field are the exact values that would be recorded in the "Complication" field on the Patient Complications form. I added the vba code below to the "Edit" command button code.
If Not IsNull(Forms![Patient Complications]![Complication]) Then
Dim comptext As String
Dim spectext As String
comptext = DLookup("[Complication Category]", "Complications", "Input = Forms![Patient Complications]![Complication]")
catcombo.Value = comptext
spectext = DLookup("[Specific Complication]", "Complications", "Input=Forms![Patient Complications]![Complication]")
speccombo.Value = spectext
End If
That solved my initial problem, but I then had an issue with the speccombo box displaying the last value it was given. For example, if speccombo.value="GI" when I click "edit", it would continue to display "GI" until another selection was made. This isn't a huge deal, just inconvenient. I wanted to make the speccombo box essentially zero out if catcombo was changed. I added the code below to fix that problem.
Private Sub catcombo_AfterUpdate()
Me.speccombo.Requery
Me.speccombo.Value = Null
End Sub
Please let me know if I need to provide clarification for anything.