Results 1 to 8 of 8
  1. #1
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568

    Insert into field Tempvar using query

    Hi,

    i am building append query with SQL:

    Code:
    INSERT INTO tb_Main ( Cause, NAZWISKO, IMIE, Pesel, Data_korekty, Login )
    SELECT DISTINCT tbl_Export.BLAD, tbl_Export.NAZWISKO, tbl_Export.IMIE, tbl_Export.Nr_dokumentu, tbl_Export.krzyzyki, [ZmienneTymczasowe]!Username AS Login
    FROM tbl_Export
    WHERE (((IsNull([tbl_Export].[Nr_dokumentu]))=False));
    This is working ok excluding [Tempvars]!Username...

    How should i write in?

    Best Wishes,
    Jacek

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    dont know where the temp var is coming from,
    but I have my username on the form (invisible) when the form opens.

    txtUser = Environ("Username")

    then I can run queries off that:
    select forms!myForm!txtUser from table....

  3. #3
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    Thank you ranman256!

    Hmm temvar is coming from login form.

    I can use txbox with tempvar like you but there is no possible to write an expression within QUery?

    Jacek

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    I agree with ranman, I always have the user information on the main form, then I can refer to it whenever I need it on forms/queries/reports.

  5. #5
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    Hi, you can use it without putting it on a form creating this simple function in VBA:

    Public Function GetUsername() As String
    GetUsername = Environ("username")
    End Function

    In your query you can use the function Getusername() in a similar way as you do with the date() function

  6. #6
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    Thank you Guys,

    NoellaG solution is working !!

    Best Wishes,
    Jacek

  7. #7
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Yes, that was a good solution. Just a warning, however, functions in queries are very slow so if you have more than 100 records the query will take a long time to run. Remember that for future functions.

  8. #8
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    Thank you aytee111,

    so if i will use tempvars in my query it could also make my queries slower.
    So the best approach will be using reference to a form i think...

    Thank you Guys,
    Best wishes,
    Jacek

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

Similar Threads

  1. tempvar and query criteria
    By Jen0dorf in forum Access
    Replies: 2
    Last Post: 07-23-2016, 10:43 AM
  2. Replies: 4
    Last Post: 06-02-2015, 09:39 AM
  3. Replies: 7
    Last Post: 04-29-2015, 10:57 AM
  4. tempvar update query date field
    By raffi in forum Queries
    Replies: 2
    Last Post: 09-27-2014, 11:51 PM
  5. Condition if there is a tempvar
    By Ruegen in forum Programming
    Replies: 1
    Last Post: 11-18-2013, 05:06 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