Form Details section loading blank after change in VBA - forms

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.

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(...)

Access text box visible depending on combo box value

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

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

Libreoffice Calc run macro with HYPERLINK

I'm trying to use hyperlinks instead of buttons to run Basic macros. It seems to be more natural to me because hyperlinks are directly connected to a cell and buttons are not.
I'm using the following Formula:
=HYPERLINK("vnd.sun.star.script:Standard.Module1.Test?language=Basic&location=document";"Check")
It should call the Subroutine Test placed in the document's macros under Standard.Module1 and display the Text 'Check' in the Cell it is written.
This works absolutely fine with libreoffice 3.6.1.2 but it doesn't work at all with version 4.1.4.2. I can't see any errors it just happens nothing at all. I tried to simply click the Hyperlink and also to hold CTRL and click it. Same result - nothing.
When I use a button the macro works as expected.
Does anyone know how to solve this problem?
This seems to be a bug in Calc. The protocol vnd.sun.star.script runs in hyperlink URLs in Writer still in version 4.2. But in Calc it runs not.
As a workaround you could have the following function attached to the sheet event "Double click". Then the macro runs if you double click the cell with the =HYPERLINK formula.
The last two versions are the results of my first ideas. I will let them in the answer because of comprehensibility reasons. But this last version is the best workaround in my opinion. It will closest work like the original vnd.sun.star.script: URL.
public function Doubelclicked(target) as Boolean
if left(target.formula, 32) = "=HYPERLINK(""vnd.sun.star.script:" then
sFormulaHyperlink = target.formula
sMacroURLRaw = mid(sFormulaHyperlink, 13, instr(13, sFormulaHyperlink, ";") - 13)
target.formula = "=""" & sMacroURLRaw
sMacroURL = target.string
target.formula = sFormulaHyperlink
oDisp = createUnoService("com.sun.star.frame.DispatchHelper")
dim args(0) as new com.sun.star.beans.PropertyValue
args(0).Name = "URL"
args(0).Value = sMacroURL
oFrame = ThisComponent.CurrentController.Frame
oDisp.executeDispatch(oFrame, sMacroURL, "", 0, args)
end if
Doubelclicked = false
end function
Here are the previous versions:
public function Doubelclicked(target) as Boolean
if left(target.formula, 32) = "=HYPERLINK(""vnd.sun.star.script:" then
sMacroURL = mid(target.formula, 13, instr(13, target.formula, chr(34))-13)
oDisp = createUnoService("com.sun.star.frame.DispatchHelper")
oFrame = ThisComponent.CurrentController.Frame
oDisp.executeDispatch(oFrame, sMacroURL, "", 0, Array())
end if
Doubelclicked = false
end function
With this it is not possible to pass parameters in the macro URL. But if it only is the goal to get the address of the cell from which the macro was called, then this is possible because we have the target of the double click. So i have updated my workaround.
public function Doubelclicked(target) as Boolean
if left(target.formula, 32) = "=HYPERLINK(""vnd.sun.star.script:" then
lStartLocation = instr(13, target.formula,"&location=")
if lStartLocation > 0 then
lEndLocation = instr(lStartLocation + 1, target.formula,"&")
if lEndLocation = 0 then lEndLocation = instr(lStartLocation + 1, target.formula,"""")
sMacroURL = mid(target.formula, 13, lEndLocation - 13)
'msgbox sMacroURL
oDisp = createUnoService("com.sun.star.frame.DispatchHelper")
dim args(2) as new com.sun.star.beans.PropertyValue
args(0).Name = "TargetAddress"
args(0).Value = target.AbsoluteName
oFrame = ThisComponent.CurrentController.Frame
oDisp.executeDispatch(oFrame, sMacroURL, "", 0, args)
end if
end if
Doubelclicked = false
end function
Greetings
Axel

Combobox Dependant on Checkbox

I have been able to change the list (or RowSource) of a Combobox dependant on whether an Optionbox has been selected using the following code:
Private Sub optYes_Click()
Options
End Sub
Private Sub optNo_Click()
Options
End Sub
Private Sub Options()
Select Case True
Case optYes.Value = True
cmb.Enabled = True
cmb.RowSource = "=Options!A1:A4"
Case optNo.Value = True
cmb.Enabled = False
End Select
End Sub
I would like to modify this slightly so that the Combobox list is limited to a group of Checkboxes that have been selected. So if I have 10 checkboxes denoting different options, and the user only selects 4 of them, then only those 4 will appear in the Combobox.
Here's how I would do it:
Private Sub Algeria_Change()
Options
End Sub
Private Sub Bangladesh_Change()
Options
End Sub
Private Sub Canada_Change()
Options
End Sub
Private Sub Denmark_Change()
Options
End Sub
Private Sub Options()
Dim names As Variant, name As Variant
Dim old As String
names = Array("Algeria", "Bangladesh", "Canada", "Denmark")
old = cmb
cmb.Clear
cmb.Enabled = False
For Each name In names
If Me.Controls(name) Then
cmb.AddItem Me.Controls(name).Caption
cmb.Enabled = True
If name = old Then cmb.SelText = old
End If
Next name
End Sub
If you need more checkboxes just add their name to names and call Options when they change.