none
Help with line of code RRS feed

  • Question

  • I'm a newbie.  Getting a compile error for syntax error on this line of code in access 2013: 

    If .Value  .OldValue Than 

    There are 2 spaces between .Value and .OldValue.  Should there be only one space?  Is that the problem or is it something else? 

    Thanks 

    Friday, March 2, 2018 2:39 PM

All replies

  • Aren't you missing the condition?

    https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/if-then-else-statement

    =, <>, >, <


    If this post answered or helped you find the answer to your question, please mark it as such for other Forum users knowledge.

    Friday, March 2, 2018 2:53 PM
  • And unless it's just a typo, "Than" should be spelled "Then" (with an 'e'). In other words:

    If .Value = .OldValue Then

    Hope it helps...

    Friday, March 2, 2018 3:41 PM
  • You need to specify which control on the form you are comparing the Old Value to. Lets say you have a form open and that form has a textbox control named MyTextbox. Then if you want to compare the MyTexbox current value to the previous value, then:

    If Me.MyTextbox = Me.Textbox.OldValue Then

    Specify what to do

    Else

    Do something else

    End If

    Friday, March 2, 2018 4:21 PM
  • We really need to see the entire procedure. There are too many factors involved to give you a direct answer.

    First, if the line is actually:

    If .Value  .OldValue Then 

    It should be:

    If .Value = .OldValue Then 

    But that assumes the surrounding code is:

    With Me.ControlNameGoesHere
        If .Value = .OldValue Then 
           'Do something
        Else
            'Do something else
        End If
    End With
    If you plan on using VBA you really need to learn the basic syntax first. There are lots of Access VBA books available.


    Bill Mosca
    www.thatlldoit.com
    http://tech.groups.yahoo.com/group/MS_Access_Professionals

    Friday, March 2, 2018 5:05 PM
  • Hi dkelley1967,

    Is your issue is solved now?

    I find that you did not done any follow up after creating this thread.

    If your issue is fixed by you then I suggest you to post your solution and mark it as an answer.

    If your issue is still exist then try to refer the suggestions given by the community members.

    If you think that the suggestions given by the community member can solve your issue then mark the helpful suggestion as an answer.

    It will help us to close this thread and it also can be helpful to other community members who will meet with same kind of issues in future.

    If you have any further questions then you can let us know about it, We will try to provide you further suggestions to solve it.

    I suggest you to update the status of this thread and take appropriate actions to close it.

    Thanks for your understanding.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 12, 2018 9:27 AM
    Moderator