Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2010
    Posts
    2

    Demystifying VB code





    Hiiiii
    I'm a complete and utter newbie to the world of VB programming within databases. I followed a textbook to create a database and have used a pile of code. However, the textbook is AWFUL at explaining what this code does...so I basically have a load of code within the database that I'm unsure of. Can any1 help me to understand what is going on? I'm not in any rush or anything, as I'm just doing this to try and learn some VB.
    Many thanks in advance...

    (sorry about the mass of code)

    Code:
    Option Compare Database
    Option Explicit
    Dim rs As DAO.Recordset
    Dim dtDOB As Date
    Dim lngPeopleTypID As Long
    Dim lngPeopleId As Long
    Dim lngParentId As Long
    Dim lngParentStudentId As Long
    Dim strStartSql As String
    Dim strWhereSql As String
    Dim strSortOrder As String
    Dim strSql As String
    Dim strCurCtrlName As String
    Dim strFilterVal As String
    Dim strMsg As String
     
    Dim varRecCnt, vbResponse
     
    Function ShowHideCtrls(Status As Boolean)
    Me.cboPeopleTypeID.Visible = Status
    Me.cboGenderID.Visible = Status
    Me.chkActive.Visible = Status
    Me.cboTitleID.Visible = Status
    Me.txtFirstName.Visible = Status
    Me.txtMiddleName.Visible = Status
    Me.txtSurname.Visible = Status
    Me.txtAddressLine1.Visible = Status
    Me.txtAddressLine2.Visible = Status
    Me.txtTown.Visible = Status
    Me.txtState.Visible = Status
    Me.txtCounty.Visible = Status
    Me.txtPostCode.Visible = Status
    Me.txtTel.Visible = Status
    Me.txtMobile.Visible = Status
    Me.txtEMail.Visible = Status
    Me.txtWeb.Visible = Status
    Me.txtDateofBirth.Visible = Status
    Me.txtAge.Visible = Status
    If Me.cboPeopleTypeID = 2 Then    'Student
        Me.cboGrade.Visible = Status
    Else
        Me.cboGrade.Visible = False
    End If
    Me.lblReqd0.Visible = Status
    Me.lblReqd1.Visible = Status
    Me.lblReqd2.Visible = Status
    Me.lblReqd3.Visible = Status
    Me.cmdUndo.Visible = Status
    Me.cmdSave.Visible = Status
    Me.cmdCancel.Visible = Status
    Me.cmdClose.Enabled = Not Status
    Me.lstPeople.Locked = Status
    Me.cboPeopleType.Locked = Status
    Me.lstStudentParents.Locked = Status
    If Status = True Then
        Me.cmdRemove.Enabled = Not Status
        Me.cmdLinkParentToStudent.Enabled = Not Status
        Me.cmdAddParent.Enabled = Not Status
    End If
    Me.lstParentsInDb.Locked = Status
    Me.txtParentFilter.Locked = Status
    If Status = True Then
        If Me.txtParentFilter > "" Then
            Me.cmdClrFltr.Enabled = True
        Else
            Me.cmdClrFltr.Enabled = False
        End If
    Else
        Me.cmdClrFltr.Enabled = False
    End If
    End Function
     
    Function SetParentListSql()
    Dim lngParentInDbId As Long
    lngPeopleId = Me.lstPeople
    'strStartSql = "SELECT tblPeople.PeopleID, tblPeople!Surname & "", "" & tblPeople!FirstName & "" "" & " _
                & "tblPeople!MiddleName AS Name, tblPeople.Town, tblPeople.Tel AS Phone, tblPeople.Mobile AS " _
                & "Cell FROM tbluPeopleType RIGHT JOIN tblPeople ON tbluPeopleType.PeopleTypeID = " _
                & "tblPeople.PeopleTypeID WHERE tblPeople.PeopleID Not In (SELECT tblPeople.PeopleID FROM " _
                & "tblParentStudentLink INNER JOIN tblPeople ON tblParentStudentLink.ParentID = " _
                & "tblPeople.PeopleID WHERE (((tblPeople.PeopleTypeID)=1) AND ((tblParentStudentLink.StudentID)=" _
                & "" & lngPeopleId & "));) AND ((tblPeople.PeopleTypeID)=1"
    strStartSql = "SELECT tblPeople.PeopleID, tblPeople!Surname & "", "" & tblPeople!FirstName & "" "" & " _
                & "tblPeople!MiddleName AS Name, tblPeople.Town, tblPeople.Tel AS Phone, tblPeople.Mobile AS " _
                & "Cell FROM tbluPeopleType RIGHT JOIN tblPeople ON tbluPeopleType.PeopleTypeID = " _
                & "tblPeople.PeopleTypeID WHERE tblPeople.PeopleID Not In (SELECT tblPeople.PeopleID FROM " _
                & "tblParentStudentLink INNER JOIN tblPeople ON tblParentStudentLink.ParentID = " _
                & "tblPeople.PeopleID WHERE (((tblPeople.PeopleTypeID)=1) AND ((tblParentStudentLink.StudentID)=" _
                & "" & lngPeopleId & "));) AND tblPeople.PeopleTypeID=1"
    If Me.ActiveControl.Name = "txtParentFilter" Then
        If Me.txtParentFilter.Text > "" Then
            strFilterVal = Me.txtParentFilter.Text
            strWhereSql = " AND tblPeople.Surname Like """ & strFilterVal & "*"""
        Else
            strWhereSql = ""
        End If
    End If
    strSortOrder = " ORDER BY tblPeople.Surname;"
    strSql = strStartSql & strWhereSql & strSortOrder
    With Me.lstParentsInDb
        .Value = Null
        .RowSource = strSql
    End With
    End Function
     
    Function ManageActiveLabel()
    If Me.chkActive = True Then
        Me.lblActive.Caption = "Active"
    Else
        Me.lblActive.Caption = "Inactive"
    End If
    End Function
     
    Public Function SetPeopleListSql()
    If Me.cboPeopleType = 2 Then    'Student selected
        strStartSql = "SELECT tblPeople.PeopleID, tblPeople!Surname & "", "" & " _
                    & "tblPeople!FirstName & "" "" & tblPeople!MiddleName AS Name, " _
                    & "tblPeople.Town, tbluPeopleType.PeopleType AS Type, " _
                    & "tblPeople.Grade FROM tbluPeopleType RIGHT JOIN tblPeople " _
                    & "ON tbluPeopleType.PeopleTypeID=tblPeople.PeopleTypeID"
    Else
        strStartSql = "SELECT tblPeople.PeopleID, tblPeople!Surname & "", "" & " _
                    & "tblPeople!FirstName & "" "" & tblPeople!MiddleName AS Name, " _
                    & "tblPeople.Town, tbluPeopleType.PeopleType AS Type " _
                    & "FROM tbluPeopleType RIGHT JOIN tblPeople ON " _
                    & "tbluPeopleType.PeopleTypeID = tblPeople.PeopleTypeID"
    End If
    If Me.cboPeopleType > 0 Then
        lngPeopleTypID = Me.cboPeopleType
        strWhereSql = " WHERE tblPeople.PeopleTypeID = " & lngPeopleTypID & ""
    Else
        strWhereSql = ""
    End If
    If Me.ActiveControl.Name = "txtStudentFilter" Then
        If Me.txtStudentFilter.Text > "" Then
            strFilterVal = Me.txtStudentFilter.Text
            If strWhereSql > "" Then
                strWhereSql = strWhereSql & " AND tblPeople.Surname Like """ & strFilterVal & "*"""
            Else
                strWhereSql = " WHERE tblPeople.Surname Like " & strFilterVal & ""
            End If
            
        End If
    End If
    strSortOrder = " ORDER BY tblPeople.Surname;"
    strSql = strStartSql & strWhereSql & strSortOrder
    Me.lstPeople.RowSource = strSql
    End Function
    Function ManageSaveButton()
    If Me.cboPeopleTypeID > 0 And Not IsNull(Me.txtFirstName) And Not IsNull(Me.txtSurname) Then
        Me.cmdSave.Enabled = True
    Else
        Me.cmdSave.Enabled = False
    End If
    End Function
     
    Function ManageDeleteButton()
    'Note:  Only People who have not been associated with other tables in the
    '       applicaiton can be deleted if they cannot be deleted they could be
    '       deactivated
    'have to check two tables to see if the currently selected Id has been used
    If Me.lstPeople > 0 Then
        'read the selected ID value
        lngPeopleId = Me.lstPeople
        
        'check the "tblStudentClassesLink" table
        'check the "tblParents" table
        varRecCnt = DCount("PeopleId", "tblPeople", "PeopleId = " & lngPeopleId & "")
        If varRecCnt > 0 Then
            Me.cmdDelete.Enabled = False
        Else
            Me.cmdDelete.Enabled = True
        End If
        'varRecCnt = DCount("StudentsClassesID", "tblStudentClassesLink", "PeopleID = " & lngPeopleId & "")
        strSql = "SELECT Count(tblStudentClassesLink.StudentClassID) AS CountOfStudentClassID " _
               & "FROM tblStudentClassesLink WHERE (((tblStudentClassesLink.PeopleID)=" & lngPeopleId & "));"
        Set rs = CurrentDb.OpenRecordset(strSql)
        varRecCnt = rs.Fields("CountOfStudentClassID").Value
        rs.Close
        Set rs = Nothing
        If varRecCnt > 0 Then
            Me.cmdDelete.Enabled = False
        Else
            Me.cmdDelete.Enabled = True
        End If
    End If
    End Function
     
    Private Sub cboGenderID_AfterUpdate()
    ManageSaveButton
    Me.cmdUndo.Enabled = True
    End Sub
     
    Private Sub cboGenderID_Change()
    Me.cmdUndo.Enabled = True
    End Sub
     
    Private Sub cboGrade_AfterUpdate()
    ManageSaveButton
    End Sub
     
    Private Sub cboGrade_Change()
    Me.cmdUndo.Enabled = True
    End Sub
     
    Private Sub cboPeopleType_AfterUpdate()
    SetPeopleListSql
    Me.lstPeople.Value = Null
    Me.cmdEdit.Enabled = False
    Me.cmdDelete.Enabled = False
    End Sub
     
    Private Sub cboPeopleTypeID_AfterUpdate()
    ManageSaveButton
    If Me.cboPeopleTypeID = 2 Then  'Student selected
        Me.cboGrade.Visible = True
    Else
        Me.cboGrade.Visible = False
    End If
    End Sub
     
    Private Sub cboPeopleTypeID_Change()
    Me.cmdUndo.Enabled = True
    End Sub
     
    Private Sub cboTitleID_AfterUpdate()
    ManageSaveButton
    Me.cmdUndo.Enabled = True
    End Sub
     
    Private Sub cboTitleID_Change()
    Me.cmdUndo.Enabled = False
    End Sub
     
    Private Sub chkActive_AfterUpdate()
    ManageActiveLabel
    ManageSaveButton
    Me.cmdUndo.Enabled = True
    End Sub
     
    Private Sub cmdAdd_Click()
    DoCmd.GoToRecord , , acNewRec
    ShowHideCtrls True
    If Me.cboPeopleType > 0 Then
        Me.cboPeopleTypeID = Me.cboPeopleType
        Me.cboGenderID.SetFocus
        Me.cboGrade.Visible = True
    Else
        Me.cboPeopleTypeID.SetFocus
    End If
    Me.cmdAdd.Enabled = False
    Me.cmdEdit.Enabled = False
    Me.cmdDelete.Enabled = False
    Me.cmdAddParent.Enabled = False
    End Sub
     
    Private Sub cmdAddParent_Click()
    DoCmd.OpenForm "frmManageParents", , , , acFormAdd, , "AddMode"
    End Sub
     
    Private Sub cmdCancel_Click()
    If Me.Dirty Then
        Me.Undo
    End If
    With Me.cmdAdd
        .Enabled = True
        .SetFocus
    End With
    If Me.lstPeople > 0 Then
        Me.cmdEdit.Enabled = True
        Me.cmdAddParent.Enabled = True
    Else
        Me.cmdEdit.Enabled = False
        Me.cmdAddParent.Enabled = False
    End If
    ManageDeleteButton
    ShowHideCtrls False
    End Sub
    Private Sub cmdClearFilter_Click()
    With Me.txtStudentFilter
        .SetFocus
        .Value = Null
    End With
    Me.cmdClearFilter.Enabled = False
    SetPeopleListSql
    End Sub
     
    Private Sub cmdClose_Click()
    If Me.OpenArgs = "FromMainMenu" Then
        If IsLoaded("frmMainMenu") Then
            Forms!frmMainMenu.Visible = True
        Else
            DoCmd.OpenForm "frmMainMenu"
        End If
    ElseIf IsLoaded("frmAdminOps") Then
        Forms!frmAdminOps.Visible = True
    Else
        DoCmd.OpenForm "frmAdminOps"
    End If
    DoCmd.Close acForm, "frmManageStudents"
    End Sub
     
    Private Sub cmdClrFltr_Click()
    With Me.txtParentFilter
        .SetFocus
        .Value = Null
    End With
    Me.cmdClrFltr.Enabled = False
    SetParentListSql
    End Sub
     
    Private Sub cmdDelete_Click()
    If Me.lstPeople > 0 Then
        lngPeopleId = Me.lstPeople
        strMsg = "Are you sure you want to delete the selected individual?"
        vbResponse = MsgBox(strMsg, vbQuestion + vbYesNo + vbDefaultButton1, "Delete Selected Person")
        If vbResponse = vbYes Then
            strSql = "DELETE * FROM tblPeople WHERE PeopleID = " & lngPeopleId & ";"
            CurrentDb.Execute strSql
            With Me.lstPeople
                .Value = Null
                .Requery
                .SetFocus
            End With
            Me.cmdDelete.Enabled = False
            Me.cmdEdit.Enabled = False
            Me.cmdAddParent.Enabled = False
        End If
    End If
    End Sub
     
    Private Sub cmdEdit_Click()
    If Me.lstPeople > 0 Then
        lngPeopleId = Me.lstPeople
        With Me.txtPeopleID
            .Visible = True
            .SetFocus
        End With
        DoCmd.FindRecord lngPeopleId
        ShowHideCtrls True
        Me.cboPeopleTypeID.SetFocus
        Me.txtPeopleID.Visible = False
        Me.cmdAdd.Enabled = False
        Me.cmdEdit.Enabled = False
        Me.cmdDelete.Enabled = False
        Me.cmdAddParent.Enabled = False
    End If
    End Sub
     
    Private Sub cmdLinkParentToStudent_Click()
    If Me.lstPeople > 0 And Me.lstParentsInDb > 0 Then
        lngPeopleId = Me.lstPeople
        lngParentId = Me.lstParentsInDb
        Set rs = CurrentDb.OpenRecordset("tblParentStudentLink")
        rs.AddNew
        rs.Fields("StudentID").Value = lngPeopleId
        rs.Fields("ParentID").Value = lngParentId
        rs.Update
        Set rs = Nothing
        With Me.lstStudentParents
            .Value = Null
            .Requery
        End With
        With Me.lstParentsInDb
            .Value = Null
            .Requery
        End With
        Me.lstPeople.SetFocus
        Me.cmdLinkParentToStudent.Enabled = False
        Me.cmdRemove.Enabled = False
    End If
    End Sub
     
    Private Sub cmdRemove_Click()
    If Me.lstStudentParents > 0 Then
        lngParentStudentId = Me.lstStudentParents
        strSql = "DELETE * FROM tblParentStudentLink " _
               & "WHERE tblParentStudentLink.ParentStudentLinkID =" & lngParentStudentId & ";"
        CurrentDb.Execute strSql
        Me.lstPeople.SetFocus
        With Me.lstStudentParents
            .Requery
            .Value = Null
        End With
        With Me.lstParentsInDb
            .Requery
            .Value = Null
        End With
        Me.cmdRemove.Enabled = False
        Me.cmdLinkParentToStudent.Enabled = False
    End If
    End Sub
     
    Private Sub cmdSave_Click()
    If Me.Dirty Then
        Me.Dirty = False
    End If
    With Me.cmdAdd
        .Enabled = True
        .SetFocus
    End With
    If Me.lstPeople > 0 Then
        Me.cmdEdit.Enabled = True
        Me.cmdAddParent.Enabled = True
    Else
        Me.cmdEdit.Enabled = False
        Me.cmdAddParent.Enabled = False
    End If
    ManageDeleteButton
    ShowHideCtrls False
    Me.lstPeople.Requery
    End Sub
     
    Private Sub cmdUndo_Click()
    If Me.Dirty Then
        Me.Undo
    End If
    Me.cboPeopleTypeID.SetFocus
    Me.cmdUndo.Enabled = False
    Me.cmdSave.Enabled = False
    End Sub
    Private Sub Form_Current()
    If Not IsNull(Me.txtDateofBirth) Then
        dtDOB = Me.txtDateofBirth
        Me.txtAge = Age(dtDOB, Date)
    Else
        Me.txtAge = ""
    End If
    ManageActiveLabel
    Me.lstPeople.Requery
    End Sub
     
    Private Sub Form_Open(Cancel As Integer)
    Select Case bytUserSecLevel
    Case 1  'Admin User
        Me.AllowAdditions = True
        Me.AllowEdits = True
        Me.AllowDeletions = True
    Case 2  'Office Staff User
        Me.AllowAdditions = True
        Me.AllowEdits = True
        Me.AllowDeletions = True
    Case 3  'Teacher User
        Me.AllowAdditions = False
        Me.AllowEdits = False
        Me.AllowDeletions = False
    End Select
    End Sub
     
    Private Sub lstParentsInDb_AfterUpdate()
    Me.cmdLinkParentToStudent.Enabled = True
    End Sub
    Private Sub lstPeople_AfterUpdate()
    If Me.lstPeople > 0 Then
        With Me.lstStudentParents
            .Requery
            .Visible = True
            .Value = Null
        End With
        With Me.lstParentsInDb
            .Requery
            .Visible = True
            .Value = Null
        End With
        Me.txtParentFilter.Visible = True
        Me.cmdClrFltr.Visible = True
        Me.cmdEdit.Enabled = True
        Me.cmdAddParent.Visible = True
        With Me.cmdLinkParentToStudent
            .Visible = True
            .Enabled = False
        End With
        With Me.cmdRemove
            .Visible = True
            .Enabled = False
        End With
        ManageDeleteButton
    End If
    End Sub
     
    Private Sub lstPeople_DblClick(Cancel As Integer)
    Call cmdEdit_Click
    End Sub
     
    Private Sub lstStudentParents_AfterUpdate()
    If Me.lstStudentParents > 0 Then
        Me.cmdRemove.Enabled = True
    End If
    End Sub
     
    Private Sub txtAddressLine1_AfterUpdate()
    ManageSaveButton
    End Sub
     
    Private Sub txtAddressLine1_Change()
    Me.cmdUndo.Enabled = True
    End Sub
     
    Private Sub txtAddressLine2_AfterUpdate()
    ManageSaveButton
    End Sub
     
    Private Sub txtAddressLine2_Change()
    Me.cmdUndo.Enabled = True
    End Sub
     
    Private Sub txtCounty_AfterUpdate()
    ManageSaveButton
    End Sub
     
    Private Sub txtCounty_Change()
    Me.cmdUndo.Enabled = True
    End Sub
     
    Private Sub txtDateofBirth_AfterUpdate()
    If Not IsNull(Me.txtDateofBirth) Then
        dtDOB = Me.txtDateofBirth
        Me.txtAge = Age(dtDOB, Date)
    End If
    ManageSaveButton
    End Sub
     
    Private Sub txtDateofBirth_Change()
    Me.cmdUndo.Enabled = True
    End Sub
     
    Private Sub txtEmail_AfterUpdate()
    ManageSaveButton
    End Sub
     
    Private Sub txtEMail_Change()
    Me.cmdUndo.Enabled = True
    End Sub
     
    Private Sub txtFirstName_AfterUpdate()
    ManageSaveButton
    End Sub
     
    Private Sub txtFirstName_Change()
    Me.cmdUndo.Enabled = True
    End Sub
     
    Private Sub txtMiddleName_AfterUpdate()
    ManageSaveButton
    End Sub
     
    Private Sub txtMiddleName_Change()
    Me.cmdUndo.Enabled = True
    End Sub
     
    Private Sub txtMobile_AfterUpdate()
    ManageSaveButton
    End Sub
     
    Private Sub txtMobile_Change()
    Me.cmdUndo.Enabled = True
    End Sub
     
    Private Sub txtParentFilter_Change()
    SetParentListSql
    If Me.txtParentFilter.Text > "" Then
        Me.cmdClrFltr.Enabled = True
    Else
        Me.cmdClrFltr.Enabled = False
    End If
    End Sub
     
    Private Sub txtPostCode_AfterUpdate()
    ManageSaveButton
    End Sub
     
    Private Sub txtPostCode_Change()
    Me.cmdUndo.Enabled = True
    End Sub
     
    Private Sub txtStudentFilter_Change()
    SetPeopleListSql
    Me.lstPeople.Value = Null
    With Me.lstStudentParents
        .Value = Null
        .Visible = False
    End With
    With Me.lstParentsInDb
        .Value = Null
        .Visible = False
    End With
    With Me.txtParentFilter
        .Value = Null
        .Visible = False
    End With
    Me.cmdClrFltr.Visible = False
    With Me.cmdRemove
        .Default = False
        .Visible = False
    End With
    With Me.cmdLinkParentToStudent
        .Enabled = False
        .Visible = False
    End With
    Me.cmdAddParent.Visible = False
    If Me.txtStudentFilter.Text > "" Then
        Me.cmdClearFilter.Enabled = True
    Else
        Me.cmdClearFilter.Enabled = False
    End If
    End Sub
     
    Private Sub txtSurname_AfterUpdate()
    ManageSaveButton
    End Sub
     
    Private Sub txtSurname_Change()
    Me.cmdUndo.Enabled = True
    End Sub
     
    Private Sub txtTel_AfterUpdate()
    ManageSaveButton
    End Sub
     
    Private Sub txtTel_Change()
    Me.cmdUndo.Enabled = True
    End Sub
     
    Private Sub txtTown_AfterUpdate()
    ManageSaveButton
    End Sub
     
    Private Sub txtTown_Change()
    Me.cmdUndo.Enabled = True
    End Sub
     
    Private Sub txtWeb_AfterUpdate()
    ManageSaveButton
    End Sub
     
    Private Sub txtWeb_Change()
    Me.cmdUndo.Enabled = True
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Rather than someone trying to explain 100 lines of code, why don't you point out a specific example of something you don't understand, and we can explain that?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Join Date
    Apr 2010
    Posts
    2
    probably should have done that...I'll re-post as per function.
    Can any1 tell me what is going on in this 1? Any help is very much appreciated! Thanks for advice

    Code:
    Function ShowHideCtrls(Status As Boolean)
    Me.cboPeopleTypeID.Visible = Status
    Me.cboGenderID.Visible = Status
    Me.chkActive.Visible = Status
    Me.cboTitleID.Visible = Status
    Me.txtFirstName.Visible = Status
    Me.txtMiddleName.Visible = Status
    Me.txtSurname.Visible = Status
    Me.txtAddressLine1.Visible = Status
    Me.txtAddressLine2.Visible = Status
    Me.txtTown.Visible = Status
    Me.txtState.Visible = Status
    Me.txtCounty.Visible = Status
    Me.txtPostCode.Visible = Status
    Me.txtTel.Visible = Status
    Me.txtMobile.Visible = Status
    Me.txtEMail.Visible = Status
    Me.txtWeb.Visible = Status
    Me.txtDateofBirth.Visible = Status
    Me.txtAge.Visible = Status
    If Me.cboPeopleTypeID = 2 Then    'Student
        Me.cboGrade.Visible = Status
    Else
        Me.cboGrade.Visible = False
    End If
    Me.lblReqd0.Visible = Status
    Me.lblReqd1.Visible = Status
    Me.lblReqd2.Visible = Status
    Me.lblReqd3.Visible = Status
    Me.cmdUndo.Visible = Status
    Me.cmdSave.Visible = Status
    Me.cmdCancel.Visible = Status
    Me.cmdClose.Enabled = Not Status
    Me.lstPeople.Locked = Status
    Me.cboPeopleType.Locked = Status
    Me.lstStudentParents.Locked = Status
    If Status = True Then
        Me.cmdRemove.Enabled = Not Status
        Me.cmdLinkParentToStudent.Enabled = Not Status
        Me.cmdAddParent.Enabled = Not Status
    End If
    Me.lstParentsInDb.Locked = Status
    Me.txtParentFilter.Locked = Status
    If Status = True Then
        If Me.txtParentFilter > "" Then
            Me.cmdClrFltr.Enabled = True
        Else
            Me.cmdClrFltr.Enabled = False
        End If
    Else
        Me.cmdClrFltr.Enabled = False
    End If
    End Function

  4. #4
    CGM3 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Atlanta, GA
    Posts
    49
    This is a function which is passed (when called from somewhere else) a Boolean value that is either True or False, and uses that value (contained in the variable Status) to either hide (when Status is False) or show (when Status is True) a number of controls on the form (judging by the naming conventions, combo boxes and text fields and labels and a check box and some command buttons. To parse the first line --

    Me.cboPeopleTypeID.Visible = Status

    -- Me refers to the current form (I rarely use it myself), cboPeopleTypeID is (to judge by the name) a combo box control on that form, and Visible is one of its properties. If you set the Visible property to False, the combo box is no longer visible (d'uh), while if you set it to True it is visible.

    The code --

    If Me.cboPeopleTypeID = 2 Then 'Student
    Me.cboGrade.Visible = Status
    Else
    Me.cboGrade.Visible = False
    End If

    -- is an If statement that checks the currently selected Value property (I think, it's usually a good idea to show even the 'default' property) in the cboPeopleTypeID combo box and, if it is 2 (which the comment, following the single quote, indicates a Student), hides or reveals the cboGrade combo box according to the value of Status. If cboPeopleTypeID.Value is not 2, then cboGrade is hidden regardless of Status.

    The other properties set in this function are Enabled -- when True, you can enter text in a text box (unless it is Locked), activate a command button, select from a combo or list box, and so forth, while when set to False the control is "grayed out" and unresponsive (essentially, turned off) -- and Locked, which primarily applies to text fields and prevents you from entering text when True but doesn't "gray out" the field.

    Hope this helps some.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. how to get to the raw code
    By YankeeImperialistDog in forum Programming
    Replies: 1
    Last Post: 03-05-2010, 01:55 PM
  2. Help with VBA code
    By bgonzal1 in forum Access
    Replies: 3
    Last Post: 12-14-2009, 07:12 AM
  3. Access 2003 code vs Access 2007 Code
    By ralphjramirez in forum Access
    Replies: 5
    Last Post: 11-23-2009, 12:33 PM
  4. Help with VBA Code
    By access.newby in forum Forms
    Replies: 1
    Last Post: 11-15-2009, 05:43 AM
  5. Need help with code
    By hoenheim in forum Programming
    Replies: 9
    Last Post: 09-11-2008, 04:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums