dlookup and like error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • freedemi
    New Member
    • Jun 2012
    • 18

    dlookup and like error

    Hi,
    firstly, here is my code:
    Code:
    Private Sub paragelia_BeforeUpdate(Cancel As Integer)
    Dim varTemp As Variant
    Dim varTemp1 As Variant
    Dim sFilter As String
    Dim inputtext As Long
    Dim astrWhere As String
    
    
    inputtext = InStr(1, Forms![frm_kataxorisi]![paragelia], "-")
    
    sFilter = Left(Forms![frm_kataxorisi]![paragelia], inputtext - 1)
    varTemp = DLookup("[ypiresia]", "tbl_kataxorisi", "[ypiresia] = Forms![frm_kataxorisi]![ypiresia]")
    
    varTemp1 = DLookup("[paragelia]", "tbl_kataxorisi", "[paragelia] like 'sFilter'")
    
    
    If varTemp = Forms![frm_kataxorisi]![ypiresia] And varTemp1 = Forms![frm_kataxorisi]![paragelia] Then
    Me.Undo
    MsgBox "Ç ÔéìÞ áõôÞ Ý÷åé Þäç êáôá÷ùñçèåß", vbOKOnly, "Ðñïóï÷Þ Äéðëüôõðç êáôá÷þñçóç"
    Else
    MsgBox ("hi")
    End If
    
    End Sub
    I manage to take the value before (-) with sFilter(string) , but i cannot put this in dlookup function to find only values, which will consist of sFilter value.
    Thanks in advance!
    Last edited by NeoPa; Jun 19 '12, 10:09 PM. Reason: Added mandatory [CODE] tags.
  • nico5038
    Recognized Expert Specialist
    • Nov 2006
    • 3080

    #2
    Change:
    Code:
    varTemp1 = DLookup("[paragelia]", "tbl_kataxorisi", "[paragelia] like 'sFilter'")
    into

    Code:
    varTemp1 = DLookup("[paragelia]", "tbl_kataxorisi", "[paragelia] like '"& sFilter & "'")
    Nic;o)

    Comment

    • freedemi
      New Member
      • Jun 2012
      • 18

      #3
      thanks for your answer.
      Now, i dont face any problem but i cannot have that i want because if i put in field Forms![frm_kataxorisi]![paragelia] the value 1052-a, the string sFilter take the value =1052, but after that no value in vartemp1=null, and i dont why is happening.
      If i dont use like function and just take the whole field everything is ok.

      Comment

      • nico5038
        Recognized Expert Specialist
        • Nov 2006
        • 3080

        #4
        For a LIKE you need to use a "*" or "%" as wildcharacter.
        So for a match with "1052-a" you would need as LIKE string "1052%" so the code would look like:
        Code:
        varTemp1 = DLookup("[paragelia]", "tbl_kataxorisi", "[paragelia] like '"& sFilter & "%'")
        Nic;o)

        Comment

        • freedemi
          New Member
          • Jun 2012
          • 18

          #5
          thanks again.
          I try this, but nothing happening.
          Lets say that when i write (1052/12-a or 1234-5 or 1052-f), i take as sFilter= 1052/12 or 1234 or 1052 and i want to search my table.[paragelia], so as to see if there is a value which will consist of these values.
          In my table i have values 1052/12-a-b, 1052-b, 1234.

          Comment

          • nico5038
            Recognized Expert Specialist
            • Nov 2006
            • 3080

            #6
            Can you place a breakpoint in the code (click in left ruler) and execute the code till the DLOOKUP.
            Next type in the immediate window at the bottom:
            Code:
            ?"[paragelia] like '"& sFilter & "%'"
            and report here the result.

            Nic;o)

            Comment

            • freedemi
              New Member
              • Jun 2012
              • 18

              #7
              here is my report
              [paragelia] like '1052%'

              Comment

              • freedemi
                New Member
                • Jun 2012
                • 18

                #8
                I understand my fault nico5038, after your propositions.
                I had to change my .....If varTemp = Forms![frm_kataxorisi]![ypiresia] And varTemp1 = Forms![frm_kataxorisi]![paragelia] Then...... with..... If varTemp = Forms![frm_kataxorisi]![ypiresia] And varTemp1>0 Then....., so as my code says that there is a record which catch these criterias.
                Thanks very match for your replies.
                P.S. Do you know any way to have management system about my ms access db, i want to create manually login users with permissions and i id like to have a log files.

                Comment

                • nico5038
                  Recognized Expert Specialist
                  • Nov 2006
                  • 3080

                  #9
                  I personally use regularly the windows userid of the person logged in. You can get that using the environ() function like:
                  Code:
                  strUsername = environ("username")
                  Thus I'm sure only people allowed to use the system will be able to run my access application. Placing the allowed users within the company in an authorization table will limit the access to the intended users and you can log the users starting the application.

                  Nic;o)

                  Comment

                  • freedemi
                    New Member
                    • Jun 2012
                    • 18

                    #10
                    thanks again.
                    Have a nice day!

                    Comment

                    Working...