DLookup

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mubs
    New Member
    • Mar 2007
    • 77

    #1

    DLookup

    Hi

    i am having little trouble with my events code in Access..

    I am using the following code to refer to the Availablilty field in the Add_Video table,

    Private Sub Combo33_BeforeU pdate(Cancel As Integer)
    If [Forms]![Add_Video]![Availability] = False Then
    MsgBox "Video not available"

    Else
    End If

    but as i run it i get the following msg..

    "ms access cant find the form add video referred to in a macro expression or visual basic code
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    Code:
    If [Forms]![Add_Video]![Availability] = False
    refers to a control on the form Add_Video, not ot a field in a table named Add_Video. Do you, in fact, have a form named Add_Video?

    If you have a control on your form named Availability try

    Code:
     Private Sub Combo33_BeforeUpdate(Cancel As Integer)
      If Me.Availability] = False Then
    	 MsgBox "Video not available"
      End If

    Comment

    • Mubs
      New Member
      • Mar 2007
      • 77

      #3
      thanks for reply

      i tried ur code but gor following msg..

      syntax error..

      my database is about a video rentals store..

      i have a form called rentals, and in that when a customer chooses a video, the video might not be available, this info is in the video table under the field availability.. so what i am trying to do is create an event which will tell the user that a particular video is not available when they choose to rent a video..

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        Sorry, I accidentally left a bracket in when replacing your code with mine; that's what is throwing the error:

        Code:
        Private Sub Combo33_BeforeUpdate(Cancel As Integer)
        If Me.Availability[b]][/b] = False Then
          MsgBox "Video not available"
        End If
        should be:
        Code:
        Private Sub Combo33_BeforeUpdate(Cancel As Integer)
         If Me.Availability = False Then
          MsgBox "Video not available"
         End If

        Comment

        • Mubs
          New Member
          • Mar 2007
          • 77

          #5
          it is still incorrect

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            Unless this is a snippet of code, you need End Sub at the end.

            Comment

            • Mubs
              New Member
              • Mar 2007
              • 77

              #7
              i have also tried that and get the another error msg..

              "compile error"..

              what i need to know is how you referece a field in another table and check its data type, and if its false then i want msg showing that...

              plz need asap help

              Comment

              • Rabbit
                Recognized Expert MVP
                • Jan 2007
                • 12517

                #8
                Originally posted by Mubs
                i have also tried that and get the another error msg..

                "compile error"..

                what i need to know is how you referece a field in another table and check its data type, and if its false then i want msg showing that...

                plz need asap help
                What? This sounds like a completely different question. If it is, it should be in a different thread.

                The name of the field, Availability, sounds to me as if it's a numeric rather than boolean field. If numeric then you're looking for =0, if it's boolean then = False should work.

                Comment

                • missinglinq
                  Recognized Expert Specialist
                  • Nov 2006
                  • 3533

                  #9
                  Yeah, Left End Sub of when copying and pasting!

                  Originally posted by Rabbit
                  Unless this is a snippet of code, you need End Sub at the end.

                  Comment

                  • MMcCarthy
                    Recognized Expert MVP
                    • Aug 2006
                    • 14387

                    #10
                    Originally posted by Mubs
                    i have a form called rentals, and in that when a customer chooses a video, the video might not be available, this info is in the video table under the field availability.. so what i am trying to do is create an event which will tell the user that a particular video is not available when they choose to rent a video..
                    It sounds like you're acutally looking for a DLookup. If the Video table is called Video and has a field called VideoName the code would be as follows:
                    Code:
                    Private Sub Combo33_BeforeUpdate(Cancel As Integer)
                       If DLookup("[Availability]", "Video", "[VideoName]=" & Me!Combo33) = False Then
                    	  MsgBox "Video not available"
                       End If
                    End Sub
                    Mary

                    Comment

                    • Mubs
                      New Member
                      • Mar 2007
                      • 77

                      #11
                      i have a table called Video and a field which i need to lookup is called availability... ..

                      Comment

                      • Rabbit
                        Recognized Expert MVP
                        • Jan 2007
                        • 12517

                        #12
                        Originally posted by Mubs
                        i have a table called Video and a field which i need to lookup is called availability... ..
                        This tells us nothing we don't already know. Look over the posts again and respond to the points brought up.

                        Comment

                        • Mubs
                          New Member
                          • Mar 2007
                          • 77

                          #13
                          none of the above codes are working.. i tried all of them...

                          Comment

                          • Rabbit
                            Recognized Expert MVP
                            • Jan 2007
                            • 12517

                            #14
                            You say that you have a table called Video but your first post says Add_Video, which is it?

                            What is the name of video name or ID field? Is it a text or numeric field?

                            Comment

                            • Mubs
                              New Member
                              • Mar 2007
                              • 77

                              #15
                              the name of the table is "Video"... and the field is a yes/no field, the field i need to do a dlookup is for the "Availabili ty" and thats in the "video" table..

                              Comment

                              Working...