Need help urgently RRS feed

  • Question

  • I have a task to add Mr or Mrs according to sex field in student profile and when I try to compile the program it gives me error "sub or function not defined" and it marks on "GetSex" function here is my code:

    Private Sub Form_Load()
    On Error Resume Next
    Dim StrSex As String

      StrSex = GetSex(Forms![Fr_ProfileAll]![FileNumber])
      If StrSex = "Male" Then
        TxtLowerhisher = "his"
        TxtMrMs = "Mr."
      ElseIf StrSex = "Female" Then
        TxtLowerhisher = "her"
        TxtMrMs = "Ms."
      End If

    End sub

    and I used in my report:

    & [Forms]![Fr_Dialog Rep Acceptance Letter Standard]![TxtMrMs]

    Note: the previous line is used in another report and it didn't give the same error but it works fine and shows mr or mrs according to student profile sex field.

    Thank you

    Tuesday, December 1, 2015 6:14 PM

All replies

  • I added GetSex function to my code and I got another error in another file:

    "Method or data member not found" and it marks on Me.CbClass

    Private Sub CbClass_AfterUpdate()
    Dim Db As DAO.Database
    Dim Rs As DAO.Recordset

    Set Db = CurrentDb
    Set Rs = Db.OpenRecordset("SELECT * FROM [T_Param_AccLetter] WHERE [ProgramType] = '" & Me.CbClass & "'")

    If Rs.RecordCount > 0 Then
      Me.TxPar1 = Rs![Paragraph1]
      Me.TxPar2 = Rs![Paragraph2]
      Me.TxPar3 = Rs![Paragraph3]
    End If

    End Sub


    and here is my function:

    Private Function GetSex(sFileNumber As String) As String
    Dim DbSex As DAO.Database
    Dim SrcRsSex As DAO.Recordset
    Dim StrSrcSex As String

      StrSrcSex = "SELECT * FROM [Q_Student Address] WHERE [FileNumber] = '" & sFileNumber & "'"
      Set DbSex = CurrentDb
      Set SrcRsSex = DbSex.OpenRecordset(StrSrcSex)
      GetSex = SrcRsSex![Sex]
    End Function

    • Edited by Magdy Baki Tuesday, December 1, 2015 6:44 PM
    Tuesday, December 1, 2015 6:41 PM