Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2009

    Unanswered: Data fields not appearing on screen

    I've been tidying up the code in an application I created to record accidents and incidents in the business.

    The user is presented with a form containing a list of incidents which they are permitted to see. Double-clicking one of these will open a form to view details.

    The incident can have three statuses, Open, Closed or Abandoned (where the user abandoned input during data entry - or closed without saving).

    The problem I have is that if the incident has a status of anything other than 'Open' none of the fields in the detail of the form are visible.

    On double-clicking the incident in the list form the following code is processed:

    Private Sub lstDisplayInc_DblClick(Cancel As Integer)
    Dim strIncID As String
    Dim strSQL, strSQL2, strSQL3 As String
    Me.statusline = ""
    'check there is a record to view details for
    If IsNull(lstDisplayInc.Column(0)) Or lstDisplayInc.Column(0) = "" Then
    MsgBox "There is no record selected"
    Exit Sub
    strIncID = lstDisplayInc.Column(0)
    End If

    'set the global incident id
    gstrIncident = strIncID

    'Set the recordsource to open the Inc Details form
    strSQL = "SELECT * " & _
    "FROM Incident " & _
    "WHERE (((incident.[Inc ID])= " & strIncID & "));"

    'Open Inc details form to the incident selected
    DoCmd.OpenForm "frmincident", acNormal, strSQL, , acFormEdit, acWindowNormal, "ONE"

    End Sub
    There is only one line in the detail form that addresses the status of the incident directly, allowing access to a button that sets status = 'Closed', and a tickbox to identify incidents as needing to be reported to the HSE.

    If Me.Status = "Open" Then
    ClsIncBtn.Enabled = True
    RiddorReportable.Enabled = True
    ClsIncBtn.Enabled = False
    RiddorReportable.Enabled = False
    End If
    The Form Load code:

    Private Sub Form_Load()
    On Error GoTo Err_formload
    Dim strSQL As String
    Dim iAtt, iCmmt As Integer

    blnJustClose = False

    Select Case Me.Form.OpenArgs
    Case "ADD"
    Me.Form.Caption = "Add Incident"

    Me.reported_date = Date
    Me.Status = "Open"
    Me.ReportedBY = gstrUserNm
    Me.lstIncItypes.RowSource = ""
    If IsNull(Me.reported_date) Then
    Me.reported_date = Date
    End If

    If IsNull(Me.ReportedBY) Or Me.ReportedBY = "" Then
    Me.ReportedBY = gstrUserNm
    End If
    Me.tbCmmnt.Caption = "Comments"
    Me.tbDocs.Caption = "Attachments"
    blnAddMode = True
    Case "ONE"
    Me.Form.Caption = "View Incident"
    blnAddMode = False
    'Load Initial Data
    Call LoadIncident
    Call getForward
    Call GetIncidentTypes
    Call GetAttachments
    Call SetFallsFields
    'get labels for comment and attachment tabs
    iCmmt = fCountComments()
    If iCmmt > 0 Then
    Me.tbCmmnt.Caption = "Comments (" + CStr(iCmmt) + ")"
    Me.tbCmmnt.Caption = "Comments"
    End If

    iAtt = fCountAttachments()
    If iAtt > 0 Then
    Me.tbDocs.Caption = "Attachments (" + CStr(iAtt) + ")"
    Me.tbDocs.Caption = "Attachments"
    End If
    Case Else
    MsgBox "No Mode! Closing form"
    GoTo Form_Close
    End Select

    Me.NavigationButtons = False
    Me.RecordSelectors = False
    Me.AddDocBtn.Enabled = False

    gdtToday = Date

    Call setVisibility

    Exit Sub


    MsgBox Err.Description
    Resume Exit_formload

    blnJustClose = True
    Exit Sub

    End Sub
    the LoadIncident code:

    Private Function LoadIncident()
    Dim strSQL As String
    Dim db As Database
    Dim rstIncident As DAO.Recordset
    strSQL = "select * from incident where " & Me.Filter

    Set db = CurrentDb

    Set rstIncident = db.OpenRecordset(strSQL)

    With rstIncident
    If Not .EOF And Not .BOF Then
    Me.Inc_ID.Value = .Fields("Inc ID")
    Me.IncDate.Value = .Fields("Date Of Incident")
    Me.Time_of_Incident.Value = .Fields("Time Of Incident")
    Me.Incident_Location.Value = .Fields("Incident Location")
    Me.Location_Name.Value = .Fields("Location Name")
    Me.[personNm].Value = .Fields("Person Name")
    Me.Person_Address.Value = .Fields("Person Address")
    Me.[persontype].Value = .Fields("Person Type")
    Me.PersonNHSNo.Value = .Fields("PersonNHSNo")
    Me.[Patient Number].Value = .Fields("Patient Number")
    Me.[What Happened].Value = .Fields("What Happened")
    Me.[Actions Taken].Value = .Fields("Actions Taken")
    Me.Witnesses.Value = .Fields("Witnesses")
    Me.ReportedBY.Value = .Fields("Reported By")
    Me.[reported date].Value = .Fields("Reported Date")
    Me.Contact.Value = .Fields("Contact")
    Me.RiddorReportable.Value = .Fields("Riddor Reportable")
    Me.Status.Value = .Fields("Status")
    Me.CarerInformed.Value = .Fields("CarerInformed")
    Me.StaffSick.Value = .Fields("StaffSick")
    Me.cmbRiskGroup.Value = .Fields("RiskGroup")
    Me.DateClosed.Value = .Fields("DateClosed")
    Me.cmbDrugErrLvl.Value = .Fields("DrugErrLvl")
    Me.cmbDrugErrSrc.Value = .Fields("DrugErrSrc")
    Me.txtInitialRisk.Value = .Fields("InitialRisk")
    Me.txtRemainingRisk.Value = .Fields("RemainingRisk")
    Me.cmbInitialProb.Value = .Fields("InitialProbability")
    Me.cmbInitialSig.Value = .Fields("InitialSignificance")
    Me.cmbRemainingProb.Value = .Fields("RemainingProbability")
    Me.cmbRemainingSig.Value = .Fields("RemainingSignificance")
    Me.txtReasonNoAsmt.Value = .Fields("ReasonNoAsmt")
    End If
    End With

    End Function
    The SetVisibility code, including at the top some lines I added to explicitly set the various controls visible:

    Private Function setVisibility()
    Dim idx, iCnt As Integer

    'start by setting all tabs visible
    Me.Detail.Visible = True

    Me.TabCtl92.Visible = True
    Me.TabCtl92.Enabled = True
    Me.tbIncDtl.Visible = True
    Me.tbIncDtl.Enabled = True
    Me.tbPrsn.Visible = True
    Me.tbPrsn.Enabled = True
    Me.tbCmmnt.Visible = True
    Me.tbCmmnt.Enabled = True
    Me.tbMgr.Visible = True
    Me.tbMgr.Enabled = True
    Me.tbFwd.Visible = True
    Me.tbFwd.Enabled = True
    Me.tbPvt.Visible = True
    Me.tbPvt.Enabled = True
    Me.tbDocs.Visible = True
    Me.tbDocs.Enabled = True

    Call SetPersonFields

    If blnAddMode = False Then
    Call SetViewMode
    End If

    Call CheckPermissions
    Call SetRiskColours
    'must be able to save, and add incident types
    Me.SaveBtn.Visible = True
    Me.SaveBtn.Enabled = True
    Me.AddIncTypeBtn.Enabled = True

    'reported by is always read-only
    Me.ReportedBY.Locked = True

    'riddor always editable
    Me.RiddorReportable.Enabled = True

    'fwd name and send function always available
    Me.ForwardName.Enabled = True
    sendmail.Enabled = True
    End Function
    I've tried setting the status of an incident to a non-valid value to test that it is all non-'Open' statuses that are affected. in all such instances the tab controls containing the details of the incident are invisible - the form presents as a blank white page.

    Any help would be greatly appreciated.

  2. #2
    Join Date
    Dec 2004
    Madison, WI
    Add a simple msgbox such as: msgbox "set Visibility function called here." in your functions so you can tell when they are/are not called. That will help you troubleshoot.

    Depending on how you designed the form and if 'Allow Additions' is set to false, you may not see the fields if there are no records (ie. blank white page). Changing the 'Allow Additions' to true should then show the fields if no records are retrieved and allow you to troubleshoot further.
    Last edited by pkstormy; 06-20-11 at 15:26.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Dec 2009
    Ah! Got it. There was a setting of AllowAdditions to false. This removed the app now works fine.

    Many thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts