Results 1 to 4 of 4

Thread: VBA & Field

  1. #1
    Join Date
    Jul 2005
    Posts
    39

    Unanswered: VBA & Field

    How do I set a field value as a variable in VBA code?

    given: variable is a date datatype (lets call it x)

    pseudo:
    If ( x = Now() ) Then
    <Do this...>
    Else: <Do something else>

    End If
    ================================
    RAM disk is *not* an installation procedure
    ================================

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    is this thing on a form?

    if me.myTextbox = now() then 'extremely unlikely BTW!!
    'blah
    else
    'blah
    endif

    if not on a form, how many have you got: 1 or N ?

    if 1
    if dlookup("thisField", "thisTable", "IDfield = 123") then

    if N, then you are heading for a recordset. in DAO:
    dim recs as dao.recordset
    set recs = currentdb.openrecordset("SELECT thisField FROM thisTable WHERE IDfield = 123")
    with recs
    do while not .eof
    if !thisfield = now() then 'i repeat - this is extremely unlikely to happen
    'blah
    else
    'blah
    endif
    .movenext
    loop
    end with
    set recs = nothing

    **extremely unlikely: Now() returns a datetime with one-second resolution

    izy
    currently using SS 2008R2

  3. #3
    Join Date
    Jul 2006
    Posts
    108
    i think he wanted this:
    '*field is named date1*'

    'dim X as date and set
    Dim X As Date
    X = date1.Value

    'if cmd
    If X = VBA.date Then 'if X = today
    MsgBox ("the date is today")
    Else 'if X not= today
    MsgBox ("the date is not today")
    End If

  4. #4
    Join Date
    Jul 2005
    Posts
    39
    jwalker: you hit the nail on its head..

    Thank you.
    ================================
    RAM disk is *not* an installation procedure
    ================================

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •