Access text box visible depending on combo box value - forms

I'm trying to set up a form with in access so that depending on what Value the user picks from Company combo box (Employers Rep or Contractor) depends on what set of contract Actions combo boxes and Clauses text boxes are shown. With the code below I have been able to hide them though not able to get them to become visible again.
Private Sub Company_Change()
Select Case Trim(Me.Company.Text)
Case "Employers Rep"
Me.ER_Action.Visible = True
Me.ER_Action2.Visible = True
Me.ER_Clause.Visible = True
Me.ER_Clause2.Visible = True
Case "Contract"
Me.ER_Action.Visible = True
Me.ER_Action2.Visible = True
Me.ER_Clause.Visible = True
Me.ER_Clause2.Visible = True
Case Else
Me.ER_Action.Visible = False
Me.ER_Action2.Visible = False
Me.ER_Clause.Visible = False
Me.ER_Clause2.Visible = False
Me.Con_Action.Visible = False
Me.Con_Action2.Visible = False
Me.Con_Clause.Visible = False
Me.Con_Clause2.Visible = False
End Select
Any help would be most appreciated. Thanks A.S.H this code now works. Changed this Select Case Me.Company for this Select Case Trim(Me.Company.Text).

you may like to consider this too.
Private Sub Company_Change()
Select Case Trim(Me.Company.Text)
Case "Employers Rep"
blnShowit = true
Case "Contract"
blnShowit = true
Case Else
blnShowit = false
End Select
Me.ER_Action.Visible = blnShowit
Me.ER_Action2.Visible = blnShowit
Me.ER_Clause.Visible = blnShowit
Me.ER_Clause2.Visible = blnShowit
Me.Con_Clause.Visible = blnShowit
Me.Con_Clause2.Visible = blnShowit

put your code in the Afterupdate event of your combo-box. that would do the trick

Related

Entity framework multiple where based on if not being added

Using _webDataDBContext As New WebDataEntities()
Dim results = _webDataDBContext.coverageareas.Select(Function(x) x)
If String.IsNullOrEmpty(city) = False Then
results.Where(Function(x) x.City = city)
End If
If String.IsNullOrEmpty(county) = False Then results.Where(Function(x) x.County = county)
If String.IsNullOrEmpty(state) = False Then results.Where(Function(x) x.State = state)
If String.IsNullOrEmpty(zip) = False Then results.Where(Function(x) x.Zip = zip)
Return Await results.ToArrayAsync()
End Using
Not sure why this isn't working, when my if statements are satisfied I want to append a where statement to my results.
However these where's are not being added even though the statements are satisfied. Anyone know why?
You have to assign the Where statement to the IQueryable.
results = results.Where(...)

Combobox - Validate not called

Can someone please give me a hint for the combobox use (LrView) in the lightroom sdk 6.0?
My validate function is not being called. I don't know why. Anybody a hint what I'm doing wrong?
Here is the code:
...
local validateComboboxValue = function (view, value)
outputToLog("in validate...")
if(value ~= "Ja" and value ~= "Nein") then
outputToLog("wrong value")
view.value = "Ja"
return false, "Ja", "Ungültige Eingabe"
else
outputToLog("valid value")
return true, value, ""
end
end
...
f:combo_box {
font = "<system>",
title = "enableSharing",
enabled = bind 'enableSharingEnabled',
items = {
"Ja",
"Nein"
},
value = bind 'sharingEnabled',
width = LrView.share "label_width",
immediate = true,
validate = validateComboboxValue,
},
...
I'm using Lightroom on a Windows 10 machine.

How to set defaut value for a many2one field in Odoo 9.0c?

I have customized a module that include a many2one field. Now, I would like to set the default value for that field with the codition is: [[u'bom_ids', u'!=', False]]. i have tried below code but it did not work probebly
width_id = field.Many2one('sale.order.line.width', default ='_get_width_default')
def _get_width_default(self, cr, uid, context=None):
res = self.pool.get('product.template').search(cr, uid, [(u'bom_ids', u'!=', False)], context=context)
return res and res[0] or False
default = {
'width_id' : _get_width_default,
}
Could you guy please help me to point what is the problem and how to sovle the problem and finnally get my purpose. Thank for watching
import logging
_logger = logging.getLogger(__name__)
def _get_width_default(self, cr, uid, context=None):
#REPLACE DOMAIN WITH SOMETHING RELEVANT
domain = []
res = self.pool.get('sale.order.line.width').search(cr, uid, domain, context=context)
_logger.info("PREPARING DEFAULT VALUE")
_logger.info(res)
return res[0] or False
width_id = fields.many2one('sale.order.line.width')
_defaults = {
'width_id' : _get_width_default,
}
What do you see as far as logging is concerned? Try the above code (v7 style).
Odoo9 Style (NEW API)
import logging
_logger = logging.getLogger(__name__)
def _get_width_default(self):
#REPLACE DOMAIN WITH SOMETHING RELEVANT
domain = []
res = self.env['sale.order.line.width'].search(domain)
_logger.info("PREPARING DEFAULT VALUE")
_logger.info(res)
return res[0].id or False
width_id = fields.many2one('sale.order.line.width',default=_get_width_default)

Form Details section loading blank after change in VBA

I recently made some changes in the VBA of a form, and now the Details section of the Form in Form view loads blank. I can see the header, and the number of records is listed at the bottom, but the Details section now loads blank. My assumption then is that the VBA code cause this to happen, as I changed no form settings.
I had done some trouble shooting in adding some new functions to an area of the form. Everything went fine. I then duplicated the code I used and modified it to do the same thing for a different part of the form. For context, this form is just a Review Page, it pulls data from several tables into a summary page. This hasn't been an issue before, and I confirmed with my back up that all the setting are the same, and the back-up does not have this issue. The only difference in the backup and this current form is added controls and command buttons, and some VBA. Yet the back-up loads correctly, and my new file does not. I have copied the VBA below in case something sticks out to you all that may because the issue. I did add to the VBA in the Form Load and Current sections, but it was just a duplication of code that was already there. I copied the code referencing Software and SW to say Hardware and HW. I'm not sure why that may be causing an issue. All code referencing Software was tested and worked satisfactorily, so I duplicated it all for Hardware. Somewhere in that lies the problem. I have copied all of the VBA for the entire form. Sorry for the length, but I thought it could be informative. You may notice sloppy work or inefficient use of code, as I am still new to this, but hopefully it makes sense. If I can clarify anything or explain what I was trying to accomplish with a particular function, please don't hesitate.
I greatly appreciate any assistance.
Option Compare Database
Private Sub cmdAddSWRev_Click()
Me.lstSWRevAdd.Visible = True
Me.lstSWRevDateAdd.Visible = True
Me.lstSWRevNotesAdd.Visible = True
Me.lblSwRevAdd.Visible = True
Me.lblSWRevDateAdd.Visible = True
Me.lblSWRevNotesAdd.Visible = True
Me.lstSWRev.Visible = False
Me.lstSWRevDate.Visible = False
Me.lstSWRevNotes.Visible = False
Me.lblSWRev.Visible = False
Me.lblSWRevDate.Visible = False
Me.lblSWRevNotes.Visible = False
Me.cmdSaveSWRev.Visible = True
End Sub
Private Sub cmdHWRevAdd_Click()
Me.lstHWRevAdd.Visible = True
Me.lstHWRevDateAdd.Visible = True
Me.lstHWRevNotesAdd.Visible = True
Me.lblHWRevAdd.Visible = True
Me.lblHWRevDateAdd.Visible = True
Me.lblHWRevNotesAdd.Visible = True
Me.lstHWRev.Visible = False
Me.lstHWRevDate.Visible = False
Me.lstHWRevNotes.Visible = False
Me.lblHWRev.Visible = False
Me.lblHWRevDate.Visible = False
Me.lblHWRevNotes.Visible = False
Me.cmdSaveHWRev.Visible = True
End Sub
Private Sub cmdSaveSWRev_Click()
'Create an entry in Software Revisions
Dim SerialNumberDatabase As DAO.Database
Dim tblSoftwareRevisions As DAO.Recordset
Set SerialNumberDatabase = CurrentDb
Set tblSoftwareRevisions = SerialNumberDatabase.OpenRecordset("tblSoftwareRevisions")
tblSoftwareRevisions.AddNew
tblSoftwareRevisions("SoftwareRevision").Value = Me.lstSWRevAdd
tblSoftwareRevisions("Assembly").Value = Me.PartNumber_tblUnits
tblSoftwareRevisions("SWRevDate").Value = Me.lstSWRevDateAdd
tblSoftwareRevisions("Notes").Value = Me.lstSWRevNotesAdd
tblSoftwareRevisions.Update
tblSoftwareRevisions.Close
'Add the new Software Revision ID to the existing unit in tblUnits by editing the Null SoftwareID field
Dim tblUnits As DAO.Recordset
Set tblUnits = SerialNumberDatabase.OpenRecordset("tblUnits")
tblUnits.MoveFirst
Do Until tblUnits.EOF
If tblUnits!SerialNumber = Me.lstSerialNumber And tblUnits!PartNumber = Me.lstPartNumber Then
tblUnits.Edit
tblUnits!SoftwareID = DMax("SWRevID", "tblSoftwareRevisions")
tblUnits.Update
End If
tblUnits.MoveNext
Loop
MsgBox ("The Software Revision has been added for this unit")
End Sub
Private Sub cmdSaveHWRev_Click()
'Create an entry in Software Revisions
Dim SerialNumberDatabase As DAO.Database
Dim tblHardwareRevisions As DAO.Recordset
Set SerialNumberDatabase = CurrentDb
Set tblHardwareRevisions = SerialNumberDatabase.OpenRecordset("tblHardwareRevisions")
tblHardwareRevisions.AddNew
tblHardwareRevisions("HardwareRevision").Value = Me.lstHWRevAdd
tblHardwareRevisions("Assembly").Value = Me.PartNumber_tblUnits
tblHardwareRevisions("HWRevDate").Value = Me.lstHWRevDateAdd
tblHardwareRevisions("Notes").Value = Me.lstHWRevNotesAdd
tblHardwareRevisions.Update
tblHardwareRevisions.Close
'Add the new Software Revision ID to the existing unit in tblUnits by editing the Null SoftwareID field
Dim tblUnits As DAO.Recordset
Set tblUnits = SerialNumberDatabase.OpenRecordset("tblUnits")
tblUnits.MoveFirst
Do Until tblUnits.EOF
If tblUnits!SerialNumber = Me.lstSerialNumber And tblUnits!PartNumber = Me.lstPartNumber Then
tblUnits.Edit
tblUnits!HardwareID = DMax("HWRevID", "tblHardwareRevisions")
tblUnits.Update
End If
tblUnits.MoveNext
Loop
tblUnits.Close
MsgBox ("The Hardware Revision has been added for this unit")
End Sub
Private Sub cmdSearch_Click()
DoCmd.ShowAllRecords
DoCmd.RunCommand acCmdFind
End Sub
Private Sub Form_Current()
Me.lstUnitBuiltDate.Requery
If Me.txtSerialCount.Value > 1 Then
Me.tblReportedIssues_subform_Label.Visible = True
Me.tblReportedIssues_subform.Visible = True
Else
Me.tblReportedIssues_subform_Label.Visible = False
Me.tblReportedIssues_subform.Visible = False
End If
If Me.txtRMACount.Value > 1 Then
Me.tblReportedIssues_subform1_Label.Visible = True
Me.tblReportedIssues_subform1.Visible = True
Else
Me.tblReportedIssues_subform1_Label.Visible = False
Me.tblReportedIssues_subform1.Visible = False
End If
If Me.lstSerialNumber.Value < 1 Then
Me.txtSerialNote.Visible = True
Else
Me.txtSerialNote.Visible = False
End If
Me.lstSWRevAdd.Visible = False
Me.lstSWRevDateAdd.Visible = False
Me.lstSWRevNotesAdd.Visible = False
Me.lblSwRevAdd.Visible = False
Me.lblSWRevDateAdd.Visible = False
Me.lblSWRevNotesAdd.Visible = False
Me.cmdSaveSWRev.Visible = False
Me.lstSWRev.Visible = True
Me.lstSWRevDate.Visible = True
Me.lstSWRevNotes.Visible = True
Me.lblSWRev.Visible = True
Me.lblSWRevDate.Visible = True
Me.lblSWRevNotes.Visible = True
Me.lstHWRevAdd.Visible = False
Me.lstHWRevDateAdd.Visible = False
Me.lstHWRevNotesAdd.Visible = False
Me.lblHWRevAdd.Visible = False
Me.lblHWRevDateAdd.Visible = False
Me.lblHWRevNotesAdd.Visible = False
Me.cmdSaveHWRev.Visible = False
Me.lstHWRev.Visible = True
Me.lstHWRevDate.Visible = True
Me.lstHWRevNotes.Visible = True
Me.lblHWRev.Visible = True
Me.lblHWRevDate.Visible = True
Me.lblHWRevNotes.Visible = True
End Sub
Private Sub Form_Load()
Me.lstSWRevAdd.Visible = False
Me.lstSWRevDateAdd.Visible = False
Me.lstSWRevNotesAdd.Visible = False
Me.lblSwRevAdd.Visible = False
Me.lblSWRevDateAdd.Visible = False
Me.lblSWRevNotesAdd.Visible = False
Me.cmdSaveSWRev.Visible = False
Me.lstSWRev.Visible = True
Me.lstSWRevDate.Visible = True
Me.lstSWRevNotes.Visible = True
Me.lblSWRev.Visible = True
Me.lblSWRevDate.Visible = True
Me.lblSWRevNotes.Visible = True
Me.lstHWRevAdd.Visible = False
Me.lstHWRevDateAdd.Visible = False
Me.lstHWRevNotesAdd.Visible = False
Me.lblHWRevAdd.Visible = False
Me.lblHWRevDateAdd.Visible = False
Me.lblHWRevNotesAdd.Visible = False
Me.cmdSaveHWRev.Visible = False
Me.lstHWRev.Visible = True
Me.lstHWRevDate.Visible = True
Me.lstHWRevNotes.Visible = True
Me.lblHWRev.Visible = True
Me.lblHWRevDate.Visible = True
Me.lblHWRevNotes.Visible = True
Me.lstUnitBuiltDate.Requery
End Sub
Private Sub lstRMA_Click()
MsgBox "This cannot be Edited or Altered", vbCritical, "Field Locked"
End Sub
Private Sub tblReportedIssues_subform_Enter()
MsgBox "This cannot be Edited or Altered. If you would like to review a listed RMA, please use the Search or Navigation buttons to locate it.", vbCritical, "Field Locked"
End Sub
If it matters, the form has a record source of "SELECT tblReportedIssues.*, tblUnits.Notes, tblUnits.SerialNumber AS SerialNumber_tblUnits, tblUnits.PartNumber AS PartNumber_tblUnits FROM tblUnits INNER JOIN (tblRMA INNER JOIN tblReportedIssues ON tblRMA.RMANumber = tblReportedIssues.RMA) ON (tblUnits.PartNumber = tblReportedIssues.PartNumber) AND (tblUnits.SerialNumber = tblReportedIssues.SerialNumber); "
With Settings as follows:
Record Set: Dynaset
Fetch Defaults: Yes
Filter: (blank)
Filter On Load: No
Order By: (blank)
Order on Load: No
Wait for Post Processing: No
Data Entry: No
Allow Additions: No
Allow Deletions: No
Allow Edits: Yes
Allow Filters: Yes
Record Locks: No Locks
These settings and Record Source work on my back-up file in that they allow everything to load correctly.
I'm an idiot. After much investigation, it appears I accidentally selected the Detail bar in design mode and changed its visibility to No while I was trying to hide other controls.

Require that form fields are filled before saving a record

I have a form with fourteen fields, ten of which are always required, and three of which (Other Absence Type, Illness Type and Other Illness Type) are conditionally required. There is also a Save Record button on the form, which has a subroutine meant to check that all required fields are filled before saving the record. The ten required fields have their Required property set to Yes in the table.
The code for enabling/disabling the three conditionally required fields appears to work on its own, and the sub-routine for checking if all required fields are filled also appears to work on its own. However, whenever one of the conditionally required fields is enabled but also left blank and I try to save the record, the form freezes and I can no longer make changes.
Private Sub Form_Load()
With Me
.FirstName.SetFocus
.Other_Absence_type.Enabled = False
.Illness_type.Enabled = False
.Other_Illness_type.Enabled = False
End With
End Sub
Private Sub Absence_type_Click()
If [Absence type] = "Staff illness" Then
[Illness type].Enabled = True
Else
Me.[Illness type].Value = ""
Me.[Illness type].Enabled = False
Me.[Other Illness Type].Value = ""
Me.[Other Illness Type].Enabled = False
End If
If Me.[Absence type] = "Other (Please specify)" Then
Me.[Other Absence Type].Enabled = True
Me.Other_Absence_type.SetFocus
Else
Me.[Other Absence Type].Value = ""
Me.[Other Absence Type].Enabled = False
End If
End Sub
Private Sub Illness_type_Click()
If Me.[Illness type] = "Other (Please specify)" Then
Me.[Other Illness Type].Enabled = True
Me.Other_Illness_type.SetFocus
Else
Me.[Other Illness Type].Value = ""
Me.[Other Illness Type].Enabled = False
End If
End Sub
Private Sub SaveRecordNew_Click()
On Error GoTo ErrorHandler
DoCmd.RunCommand acCmdSaveRecord
ErrorHandler:
MsgBox "One or more required fields are blank", vbExclamation
Supposing that validate() is the function that will check that every field is filled, you need to call it in the before_update event of the form. This is the function:
Function validate() as Boolean
Dim ret as Boolean
If (textbox1.Value & "") = "" or (textbox2.Value & "") = "" or ... Then
ret = false
Else
ret = true
End If
validate = ret
End Function
Before_Update form event:
Private sub Form_BeforeUpdate(cancel as integer)
If not validate() then
MsgBox "Fill all required fields, please"
cancel = true
End If
End Sub