Results 1 to 4 of 4
  1. #1
    Anacronos is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2016
    Posts
    24

    Saving a global variable to a table as a part of SQL statement using Currenddb.execute

    I was requested to save each record that has been eliminated. So in the main form I put a button which runs a SQL that copies the data to a table "Eliminated" and then proceeds to actually eliminated from that form but in this new table I need to save the time(Now()) (Field, Default value = Now()... no problem) in which it was eliminated and the name of the user I already created a logging form which saves the name of the user as string in a variable located in a module (public instead of dim) . The deal is this; I can display the name in unbound textboxes no problem. But I´m not sure how to save it along with the other fields that make up the record in the new table.


    This is the code used in the button

    Dim sql As String
    sql = "INSERT INTO Eliminados (Id, Id_dia, Nombre, Edad, Sexo, Total, Anticipo, Resta, Dirección, Telefono, Creado, Contacto, Fecha, Cont) " _
    & "SELECT DatosPaciente.Id, DatosPaciente.Id_dia, DatosPaciente.Nombre, DatosPaciente.Edad, DatosPaciente.Sexo, DatosPaciente.Total, DatosPaciente.Anticipo, DatosPaciente.Resta, DatosPaciente.Dirección, DatosPaciente.Telefono, DatosPaciente.Creado, DatosPaciente.Contacto, DatosPaciente.Fecha, DatosPaciente.Cont " _
    & "FROM DatosPaciente " _
    & "Where Id = '" & Me.txt_id & " ' "


    CurrentDb.Execute (sql)
    ' Docmd.SendObject
    DoCmd.RunCommand acCmdDeleteRecord


    Any Help will be appreciated, Thank you in advance.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Add the field to the INSERT line at the end, and concatenate the value at the end of the SELECT string, with the same delimiters you used for the ID.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Anacronos is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2016
    Posts
    24
    Excellent , It worked . Thank you

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help! By the way, normally you wouldn't delete records, you'd set a status field of some sort to flag them as deleted.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Global Variable
    By gtg430i in forum Programming
    Replies: 11
    Last Post: 03-10-2014, 05:00 PM
  2. Can't See Global Variable
    By CementCarver in forum Programming
    Replies: 12
    Last Post: 09-19-2013, 12:28 PM
  3. Global variable
    By ramdandi in forum Queries
    Replies: 3
    Last Post: 12-18-2011, 01:01 AM
  4. Username as Global Variable
    By imintrouble in forum Access
    Replies: 3
    Last Post: 10-10-2011, 10:45 AM
  5. How to declare Global Variable
    By ganeshvenkatram in forum Access
    Replies: 1
    Last Post: 06-16-2011, 05:18 AM

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