Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    509

    updating a record

    I have a table with a set of fields that is identical to the set of fields in a second table.
    The first table has and will only have one record. (the user will have the option of changing any of the entries in that record)


    The second table has many records (the user cannot modify these records, as they serve as a sort of template for the record in the first)

    Q:
    Is there a way to updates all of the fields in first table with data from a record in the second table where a criteria has been met

    something like this:
    update all of the fields in the first table with the data from the record in the second table where some field in that record = some data


    many thanks in advance,
    mark

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    yes there is. use an UPDATE query. or if it is too complicated, use recordsets in code.

  3. #3
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    509
    this newbie is not familiar with either (I tried the help tables and other web forums, but just got confused). would you be able to direct me to an example (that usually helps me alot)

    remember: the catch is that I want to update all of the fields in a record to the values of the fields in a record in an 'update to' table (both records have the exact same fields)

  4. #4
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    509
    would an SQL statement like this make any sense:

    UPDATE FirstTable
    SET * = SecondTable.*
    WHERE SecondTable.PrintOption = me.cboPrintOption;

  5. #5
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Quote Originally Posted by markjkubicki View Post
    would an SQL statement like this make any sense:

    UPDATE FirstTable
    SET * = SecondTable.*
    WHERE SecondTable.PrintOption = me.cboPrintOption;
    I don't think this will work. you need to list all fields in your query. Or you can delete and then insert, * can use in insert statement.

  6. #6
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    509
    I currently have delete and insert* statements

    The record source for the current form is the record that is being deleted, and subsequently being 'replaced' by the inserted record.

    however, when I run a me.refresh command to get the form to display the new record, I get a form of null values (which makes sense, because it's source is still pointing to a record that has been deleted). I have not been able to get it to poiont to the (new) inserted record, and to display that data.

    (the record source table will have only and never more than 1 record.)

  7. #7
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    did you try me.requery?

  8. #8
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    509
    tired that..


    heres my code (behind the AfterUpdate event):

    Dim sSQL As String
    DoCmd.SetWarnings False
    sSQL = "Delete * from [tbeFixtureSchedulePrintOptions];"
    DoCmd.RunSQL sSQL
    sSQL = "INSERT INTO tbeFixtureSchedulePrintOptions" _
    & " SELECT *" _
    & " from tblFixtureSchedulePrintOptions" _
    & " WHERE [PresetOption] = " & Me.frmPresetOption & ";"
    DoCmd.RunSQL sSQL
    DoCmd.SetWarnings True
    Me.Requery

  9. #9
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    So, you mean there does be one record in the table after delete and insert, and you still get nulls in the form after requery, right?

  10. #10
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    509
    that's correct

  11. #11
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    this looks strange to me.

  12. #12
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    509
    me too

  13. #13
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    try requery then refresh.

  14. #14
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    509
    still nothing

  15. #15
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I've modified your code. Execute the following code. What are the recults??

    Dim sSQL As String
    '==============================
    'for testing
    '==============================
    Dim R as DAO.Recordset
    Dim RC as Long 'record count

    MsgBox "Option (criteria) selected is " & Me.frmPresetOption

    sSQL = " SELECT *" _
    sSQL = sSQL & " FROM tblFixtureSchedulePrintOptions"
    sSQL = sSQL & " WHERE [PresetOption] = " & Me.frmPresetOption & ";"
    ' open recordset
    Set R = Cuttentdb.OpenRecordset(sSQL)
    RC = R.Recordcount
    R.Close
    Set R = Nothing
    MsgBox "Number of records = " & RC
    '==============================
    'end testing
    '==============================


    'clear table
    sSQL = "Delete * from [tbeFixtureSchedulePrintOptions];"
    CurrentDB.Execute sSQL, dbfailonerror
    'append new record
    sSQL = "INSERT INTO tbeFixtureSchedulePrintOptions" _
    & " SELECT *" _
    & " from tblFixtureSchedulePrintOptions" _
    & " WHERE [PresetOption] = " & Me.frmPresetOption & ";"
    CurrentDB.Execute sSQL, dbfailonerror
    'requery current form
    Me.Requery



    Steve
    --------------------------------
    "Veni, Vidi, Velcro"
    (I came; I saw; I stuck around.)

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 06-29-2010, 01:24 PM
  2. Table not updating (Anyone Please Help)
    By goyal_cyber in forum Queries
    Replies: 7
    Last Post: 05-28-2010, 09:42 AM
  3. Updating another record table with command button
    By erlan501 in forum Programming
    Replies: 5
    Last Post: 04-26-2010, 09:03 AM
  4. FE & BE Updating
    By mastromb in forum Access
    Replies: 5
    Last Post: 02-12-2010, 11:55 AM
  5. Replies: 3
    Last Post: 06-27-2009, 03:53 PM

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