Re: Simple q: setting the value of one field based on a form selection

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: John Vinson (jvinson_at_STOP_SPAM.WysardOfInfo.com)
Date: 02/05/05


Date: Sat, 05 Feb 2005 11:25:44 -0700

On Sat, 5 Feb 2005 08:05:03 -0800, "Dave Linsalata"
<DaveLinsalata@discussions.microsoft.com> wrote:

>Hey all,
>
>Newbie to VBA who is struggling along, but I've run into a minor (but
>simple) problem. I have a form that lists a number of columns from a table.
>One of the columns is uses a lookup function. I want to be able to change
>the value of another column based on the first column. Example:
>
>Table:
>Col 1 - Shape
>Col 2 - Color (lookups to: red, green, blue)
>Col 3 - Has color (bool)
>
>Form lists all tables.
>
>User goes to row 1 ("Circle") and changes the blank 'color' field to "Red".
>Access then sets 'has color' to "Yes."
>**or**
>User goes to row 1 ("Circle") and changes the 'color' field from "Red" to
>blank.
>Access then sets 'has color' to "No."
>
>I've been trying to put (ugly) code in pretty much every event handler field
>that seems relevant, but I can't get it going. Any help - even just
>guildelines saying "use AfterUpdate and look up help on [codenamehere]"...

I would strongly suggest that the "Has Color" boolean field should
simply not exist in your table. IT's redundant.

You can instead create a Query (or set the control source of a
checkbox or textbox) to

=Not IsNull([Color])

This value will be TRUE if the Color field is not NULL, False if it
is.

If you're stuck with this redundant, risky field (somebody could go
outside your form and change the value of either the [Color] or [Has
Color] fields, making your table WRONG), then use code in the combo
box's AfterUpdate event:

Private Sub Color_AfterUpdate()
Me![Has Color] = (Me!Color & "" <> "")
End Sub

                  John W. Vinson[MVP]
  
                  John W. Vinson[MVP]



Relevant Pages

  • Re: RE: User Forms
    ... workaround of just putting text labels above the ComboBox and ListBox. ... first item after their respective lists are filled. ... Private Sub FillCboBox ... For Each cCell In SrcData.Cells ...
    (microsoft.public.excel.newusers)
  • Re: Random Value...
    ... Public ListIndex As Long ... Private Sub CommandButton1_Click ... If you have multiple separate lists, ... to display the sentance in the textbox on the form. ...
    (microsoft.public.excel.programming)
  • Re: Random Value...
    ... Public ListIndex As Long ... Private Sub CommandButton1_Click ... If you have multiple separate lists, ... to display the sentance in the textbox on the form. ...
    (microsoft.public.excel.programming)
  • RE: Form or table confusion
    ... Next modify the record source of the ContactVehicleID combo to this SQL: ... add a listbox to the form (have the wizard turned on) and select the option to find the record that matches the control. ... Private Sub lboRegistrations_AfterUpdate ... With this form I can see a list of> registrations for the contact in the listbox, and the drop> down for vehicles lists only those that the contact owns. ...
    (microsoft.public.access.gettingstarted)
  • Re: Excel Script for Drop Down Menu
    ... If you're trying to put two individual lists in two cells, respectively, ... Private Sub Worksheet_SelectionChange ... Dim vArray As Variant ... .InCellDropdown = True ...
    (microsoft.public.excel.misc)