Finding if a value exists in a table

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dixie

    Finding if a value exists in a table

    I am trying to write some VBA that can check if a certain value exists in a
    field in a table. The field is a text field. The table is not a part of the
    query that forms the recordsource of the form on which I am trying to do
    this. I wish to act on the presence (or absence) of this value. What I am
    doing is trying to have a generic password form such that when you click a
    button to open the next form, the code checks if there is a letter for that
    form in the PassID field in tblPass. If there is, it opens a password form,
    if there is not, it opens the form directly without the need for a password.
    The idea is to allow clients to password any form they wish.

    For example, the code for opening a form from the current form might be ZZ.
    If the value ZZ exists in field PassID in tblPass, the password form will be
    opened. If no such value exists, the form is opened directly.

    Has anyone any ideas on how I can do this? What I seem to be missing is how
    to quiz the table to see if the value exists in that field.

    dixie


  • Allen Browne

    #2
    Re: Finding if a value exists in a table

    Dookup() should do the job.

    See:
    Getting a value from a table: DLookup()
    at:


    Put your code in the form's Open event, and cancel the event if a password
    is required and the user cannot give it.

    --
    Allen Browne - Microsoft MVP. Perth, Western Australia.
    Tips for Access users - http://allenbrowne.com/tips.html
    Reply to group, rather than allenbrowne at mvps dot org.

    "dixie" <dixiec@dogmail .com> wrote in message
    news:vmWUc.35$6 X6.2447@nnrp1.o zemail.com.au.. .[color=blue]
    >I am trying to write some VBA that can check if a certain value exists in a
    > field in a table. The field is a text field. The table is not a part of
    > the
    > query that forms the recordsource of the form on which I am trying to do
    > this. I wish to act on the presence (or absence) of this value. What I
    > am
    > doing is trying to have a generic password form such that when you click a
    > button to open the next form, the code checks if there is a letter for
    > that
    > form in the PassID field in tblPass. If there is, it opens a password
    > form,
    > if there is not, it opens the form directly without the need for a
    > password.
    > The idea is to allow clients to password any form they wish.
    >
    > For example, the code for opening a form from the current form might be
    > ZZ.
    > If the value ZZ exists in field PassID in tblPass, the password form will
    > be
    > opened. If no such value exists, the form is opened directly.
    >
    > Has anyone any ideas on how I can do this? What I seem to be missing is
    > how
    > to quiz the table to see if the value exists in that field.
    >
    > dixie
    >
    >[/color]


    Comment

    • dixie

      #3
      Re: Finding if a value exists in a table

      I feel so silly. I had already thought of a DLookup, but for some reason
      just dismissed it as not being the way to do it. It took me about 2 minutes
      to implement this after you confirmed that it WAS the way to do it.

      Thankyou.

      dixie

      "Allen Browne" <AllenBrowne@Se eSig.Invalid> wrote in message
      news:41243402$0 $22839$5a62ac22 @per-qv1-newsreader-01.iinet.net.au ...[color=blue]
      > Dookup() should do the job.
      >
      > See:
      > Getting a value from a table: DLookup()
      > at:
      > http://members.iinet.net.au/~allenbrowne/casu-07.html
      >
      > Put your code in the form's Open event, and cancel the event if a password
      > is required and the user cannot give it.
      >
      > --
      > Allen Browne - Microsoft MVP. Perth, Western Australia.
      > Tips for Access users - http://allenbrowne.com/tips.html
      > Reply to group, rather than allenbrowne at mvps dot org.
      >
      > "dixie" <dixiec@dogmail .com> wrote in message
      > news:vmWUc.35$6 X6.2447@nnrp1.o zemail.com.au.. .[color=green]
      > >I am trying to write some VBA that can check if a certain value exists in[/color][/color]
      a[color=blue][color=green]
      > > field in a table. The field is a text field. The table is not a part of
      > > the
      > > query that forms the recordsource of the form on which I am trying to do
      > > this. I wish to act on the presence (or absence) of this value. What I
      > > am
      > > doing is trying to have a generic password form such that when you click[/color][/color]
      a[color=blue][color=green]
      > > button to open the next form, the code checks if there is a letter for
      > > that
      > > form in the PassID field in tblPass. If there is, it opens a password
      > > form,
      > > if there is not, it opens the form directly without the need for a
      > > password.
      > > The idea is to allow clients to password any form they wish.
      > >
      > > For example, the code for opening a form from the current form might be
      > > ZZ.
      > > If the value ZZ exists in field PassID in tblPass, the password form[/color][/color]
      will[color=blue][color=green]
      > > be
      > > opened. If no such value exists, the form is opened directly.
      > >
      > > Has anyone any ideas on how I can do this? What I seem to be missing is
      > > how
      > > to quiz the table to see if the value exists in that field.
      > >
      > > dixie
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...