Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!
  1. Guest ji, please consider donating today!
      Become a Supporter    ::   Make a Contribution   
    Monthly Recurring Target: $300 :: Achieved: $95

Refreshing me.date

Discussion in 'Information Technology' started by realspido, Jul 28, 2006.

  1. realspido

    realspido
    Expand Collapse
    Guest

    Hi,

    DateY = Me.calCtl1.Value
    Me.Date.SetFocus
    Me.calCtl1.Visible = False

    On Error GoTo err_find
    DoCmd.FindRecord DateY, , , acUp
    Me.Refresh
    If Me.Date = DateY Then MsgBox "OK" Else MsgBox "NO"

    Exit_find:
    Exit Sub
    err_find:
    MsgBox Err.Description

    I'd like to get message "OK" if record was found or "NO" if it doesn't exist
    in database. Where am I going wrong?

    Please help.
     
  2. Wayne Morgan

    Wayne Morgan
    Expand Collapse
    Guest

    > DoCmd.FindRecord DateY, , , acUp

    You are searching up from the current location. If you want to see if it
    exits anywhere in the recordset, remove everything after DateY, this will
    search the entire recordset and do a "FindFirst".

    Also, you've used a reserved word (Date) for a field and/or control name.
    You need to enclose it in brackets to prevent any unwanted action (ex.
    Me.[Date]). It is recommended that you do NOT use reserved words for other
    that what they are designed for. In this case "date" is a VBA function.

    Also, make sure you've told VBA that DateY is a date variable. To do that,
    add the line

    Dim DateY As Date

    before you use the variable. Dim statements are usually placed near the top
    of the routine to make them easy to find. I also recommend that you go to
    Tools|Options in the VBA editor and check the box "Require Variable
    Declaration" on the Editor tab. This will cause the line "Option Explicit"
    to be added to each new module right below the "Option Compare Database"
    statement. This will force you to use Dim statements or an equivalent for
    each variable you use. This will help prevent spelling errors that may cause
    unwanted results. It has other advantages also. For any modules that already
    exists, just add the "Option Explicit" line yourself.

    --
    Wayne Morgan
    MS Access MVP


    "realspido" <realspido@discussions.microsoft.com> wrote in message
    news:F31BB8B9-C36D-48CE-93E4-59B48B45D6BA@microsoft.com...
    > Hi,
    >
    > DateY = Me.calCtl1.Value
    > Me.Date.SetFocus
    > Me.calCtl1.Visible = False
    >
    > On Error GoTo err_find
    > DoCmd.FindRecord DateY, , , acUp
    > Me.Refresh
    > If Me.Date = DateY Then MsgBox "OK" Else MsgBox "NO"
    >
    > Exit_find:
    > Exit Sub
    > err_find:
    > MsgBox Err.Description
    >
    > I'd like to get message "OK" if record was found or "NO" if it doesn't
    > exist
    > in database. Where am I going wrong?
    >
    > Please help.
     
Since you're here... we have a small favor to ask...

More people are visiting & reading SPN than ever but far fewer are paying to sustain it. Advertising revenues across the online media have fallen fast. So you can see why we need to ask for your help. Donating to SPN's is vote for free speech, for diversity of opinions, for the right of the people to stand up to religious bigotry. Without any affiliation to any organization, this constant struggle takes a lot of hard work to sustain as we entirely depend on the contributions of our esteemed writers/readers. We do it because we believe our perspective matters – because it might well be your perspective, too... Fund our efforts and together we can keep the world informed about the real Sikh Sikhi Sikhism. If everyone who writes or reads our content, who likes it, helps us to pay for it, our future would be much more secure. Every Contribution Matters, Contribute Generously!

    Become a Supporter      ::     Make a Contribution     



Share This Page