Results 1 to 7 of 7
  1. #1
    andy-29 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2012
    Location
    Culver City
    Posts
    34

    Referencing Field Names

    I need to autofill a field on a table from a field on a form.
    Table Name is Requests and Field Name to update is Status
    The user will choose from a combo box and after update should populate the corresponding field on a table.

    This is what I have (missing the table and field to update):


    Private Sub Status_AfterUpdate()
    If Not IsNull(Me.Status) Then
    ??????? = Me.Status
    End If
    End Sub

  2. #2
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows Vista Access 2003
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    If your table is the recordsource for the form, this should be done without coding.
    Just right click the combobox and select the control in the list. Second one from the top.

    If the form is not the recordsource then and update SQL should do it.

    Let me know

  3. #3
    andy-29 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2012
    Location
    Culver City
    Posts
    34
    The form is the record source. User clicks on the combo box, which then should update the corresponding record on the table.

    How do I reference the field to be populated/updated?

    Private Sub Status_AfterUpdate()
    If Not IsNull(Me.Status) Then
    [Requests.Status] = Me.Status
    End If
    End Sub

    I'm getting an error, something about invalid field. What is the correct syntax to reference the field on the table?

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I need to autofill a field on a table from a field on a form.
    There are no "fields on a form".

    Tables have fields.
    Forms have controls.
    Controls are bound or unbound.
    If a control is bound, it is bound to a field in the form recordsource - the table names are not used (unless there are two or more tables in the query, each have a field with the same name). The recordsource can be a table or a query. If the control ("Status") is a bound control, the data is automatically saved when the record is saved when you move to a different record or close the form.

    If the control is not bound, you must write code to save the data to the field in the correct record..



    -----
    "Me" is a shortcut to refer to the active form. If you have a form named "Main" and it is the active form, then to refer to a control named "MyStatus", you can use:
    Me.MyStatus
    or
    Forms!Main.MyStatus
    or
    Forms!Main!MyStatus


    If "Main is NOT the active form, you would use:
    Forms!Main.MyStatus
    or
    Forms!Main!MyStatus

  5. #5
    andy-29 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2012
    Location
    Culver City
    Posts
    34
    The content of the combo box named status will update a field(named status also) in another related table(request).

    The form which was created from a table named Marker, has a combo box named Status. What ever the user chooses on the combo box will also update a related table named Requests that has a field named also Status.

    New with access, not sure if I'm explaining it right.

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You should read the following two links (these will help in the future):

    "The Ten Commandments of Access" http://access.mvps.org/access/tencommandments.htm
    "The Evils of Look up FIELDS" http://access.mvps.org/access/lookupfields.htm

    Lookup fields are bad, combo boxes are good
    ------


    I would name the combo box "cboStatus" and the fields I would name "MarkerStatus" and "RequestsStatus".

    The combo box on the form should be bound to the field "MarkerStatus".

    To update the field "RequestsStatus", you have 3 options:
    1) The recordsouce for the form that has the combo box "cboStatus" would include the table "Requests" (in a relationship).
    2) A open form with the recordsource that includes the table "Requests" and control bound to the field "RequestsStatus".
    3) Code to find and update the correct record in the table "Requests".

  7. #7
    andy-29 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2012
    Location
    Culver City
    Posts
    34
    Thanks Steve,

    I redesigned the db and used option #2.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 06-13-2012, 06:00 PM
  2. Referencing a query field
    By rcrobman in forum Queries
    Replies: 5
    Last Post: 04-29-2011, 04:06 PM
  3. Referencing A Form Field In A Report
    By CGM3 in forum Reports
    Replies: 5
    Last Post: 07-01-2010, 08:16 PM
  4. Replies: 3
    Last Post: 06-23-2010, 02:02 PM
  5. Referencing table data in field validation rule
    By toad848 in forum Database Design
    Replies: 3
    Last Post: 03-19-2009, 07:03 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums