Welcome to SPN

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

Sign Up Now!

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.
     

Share This Page