equals to not working! (1 Viewer)

monk_1987

Registered User.
Local time
Today, 07:44
Joined
Oct 5, 2012
Messages
31
Hi there everyone

I have a problem with some code that does not work and I am beginning to pull my hair out, so any help would be appreciated.

The problem is on the line If Forms!F_Overall_MainMenu!IDStaff = FindTutorTxtBox Then When both numbers are the same it does not execute what I have told it to do. If for example I change the code to If Forms!F_Overall_MainMenu!IDStaff = "1" Then it works fine. The code I use is below.

Thanks in advance!


e = Nz(DLookup("LessonDate", "T_PrivatePupils_Lessons", "[ID_Contact] = Forms!F_Overall_Contacts!IDCONTACT"), "")

If Forms!F_Overall_MainMenu!EditRecordTickBox = True Then
MsgBox "You can't view another record while the current record has not been saved", vbOKOnly
Else
FindTutorTxtBox = Nz(DLookup("ToughtBy", "T_Contacts", "[IDCONTACT] = Forms!F_Overall_Contacts!IDCONTACT"), "")
FindTutorMainMenuTxtBox = Forms!F_Overall_MainMenu!IDStaff
If Forms!F_Overall_MainMenu!IDStaff = FindTutorTxtBox Then
If e = "" Then
response = MsgBox("Are you sure you want to create the first lesson for " & FirstName & " " & LastName & "?", vbQuestion + vbYesNoCancel)
If response = vbYes Then
Forms!F_Overall_MainMenu!EditRecordTickBox = True
DoCmd.OpenForm "F_PrivatePupils_NewLesson"
End If
Else
response = MsgBox("Are you sure you want to create a new lesson for " & FirstName & " " & LastName & "?", vbQuestion + vbYesNoCancel")
If response = vbYes Then
Forms!F_Overall_MainMenu!EditRecordTickBox = True
DoCmd.OpenForm "F_PrivatePupils_NewLesson"
End If
End If
Else
MsgBox "You are not the tutor for this contact", vbOKOnly
End If
End If
 

JHB

Have been here a while
Local time
Today, 08:44
Joined
Jun 17, 2012
Messages
7,732
Is FindTutorTxtBox a control in the form, (if yes then use Me. in front of it)?
You write it works if you put in a hardcoded string value, (="1"), then try the below:
Code:
If Forms!F_Overall_MainMenu!IDStaff = CStr(Me.FindTutorTxtBox)
 

jdraw

Super Moderator
Staff member
Local time
Today, 02:44
Joined
Jan 23, 2006
Messages
15,378
You should download and use the free utility SmartIndenter.
I have used it to reformat your code to help readers.

Code:
Sub Noname() 'note full code not posted by OP



    E = Nz(DLookup("LessonDate", "T_PrivatePupils_Lessons", "[ID_Contact] = Forms!F_Overall_Contacts!IDCONTACT"), "")

    If Forms!F_Overall_MainMenu!EditRecordTickBox = True Then
        MsgBox "You can't view another record while the current record has not been saved", vbOKOnly
    Else
        FindTutorTxtBox = Nz(DLookup("ToughtBy", "T_Contacts", "[IDCONTACT] = Forms!F_Overall_Contacts!IDCONTACT"), "")
        FindTutorMainMenuTxtBox = Forms!F_Overall_MainMenu!IDStaff
        If Forms!F_Overall_MainMenu!IDStaff = FindTutorTxtBox Then
            If E = "" Then
                response = MsgBox("Are you sure you want to create the first lesson for " & FirstName & " " & LastName & "?", vbQuestion + vbYesNoCancel)
                If response = vbYes Then
                    Forms!F_Overall_MainMenu!EditRecordTickBox = True
                    DoCmd.OpenForm "F_PrivatePupils_NewLesson"
                End If
            Else
                response = MsgBox("Are you sure you want to create a new lesson for  " & FirstName & "  " & LastName & " ?", vbQuestion + vbYesNoCancel)
                If response = vbYes Then
                    Forms!F_Overall_MainMenu!EditRecordTickBox = True
                    DoCmd.OpenForm "F_PrivatePupils_NewLesson"
                End If
            End If
        Else
            MsgBox "You are not the tutor for this contact", vbOKOnly
        End If
    End If
 End Sub

You should review the format of DLookup. There are examples here
 

monk_1987

Registered User.
Local time
Today, 07:44
Joined
Oct 5, 2012
Messages
31
That has worked a treat!! Thanks so much. Just out of curiosity... What makes that work? Don't worry if you don't fancy explaining it :) I appreciate the help!
 

JHB

Have been here a while
Local time
Today, 08:44
Joined
Jun 17, 2012
Messages
7,732
..What makes that work? Don't worry if you don't fancy explaining it :) I appreciate the help!
The IDStaff control is bound to a text field in the table.
 

Users who are viewing this thread

Top Bottom