Results 1 to 6 of 6
  1. #1
    geotrouvetout67 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2019
    Posts
    108

    Display date field from tbl when all records have the same value

    Hello,

    I'm trying to display in a form a date/time that represents when the data was last updated.

    My data is in tblFORECASTS, which contains a RefreshDate field which assigns the exact same date to each record every time the table is updated

    I want to display that date in the form but getting an error.

    In a text box I tried =[Forecasts]![RefreshDate], also =[qryRefreshDate]![FirstOfRefreshDate] and this does not work.

    The following somewhat worked, adding "SELECT First(Forecasts.RefreshDate) AS RefreshDate FROM Forecasts;" or qryRefreshDate as Record Source of the form, this worked as of displaying the date/time but it's locking the table so when I click on the "refresh db" button I get an error message that the table is already locked.

    I also tried putting that date in itself on a 1 record table and it does not work either, getting #Name?



    it's probably very simple, What am I missing?

    thanks

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,538
    Perhaps you just need to use RefreshDate as the Control Source of your textbox
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    geotrouvetout67 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2019
    Posts
    108
    This works if I assign a table or a query to the form but it locks the table where the record is which prevents me then from refreshing that table.
    I even tried adding "close window" at the beginning of the refresh macro and it still gives me that table is locked by process error.

    However if the form is closed, the macro in itself runs fine, it just bugs when the form is already open despite having a close window command at the top of the events chain.

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,538
    Quote Originally Posted by geotrouvetout67 View Post
    This works if I assign a table or a query to the form but it locks the table where the record is which prevents me then from refreshing that table.
    I even tried adding "close window" at the beginning of the refresh macro and it still gives me that table is locked by process error.

    However if the form is closed, the macro in itself runs fine, it just bugs when the form is already open despite having a close window command at the top of the events chain.
    I didn't see any mention of a macro in your original post and like most serious users I do not use them. I prefer to use VBA code. I think you will need to post a copy of your DB for me to be able to offer anything more in the way of help.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    geotrouvetout67 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2019
    Posts
    108
    Quote Originally Posted by Bob Fitz View Post
    I didn't see any mention of a macro in your original post and like most serious users I do not use them. I prefer to use VBA code. I think you will need to post a copy of your DB for me to be able to offer anything more in the way of help.
    I use both VBA and macros, sometimes macros are easier for me as I'm beginning with VBA coding.

    I think this is bugging because I have lots of VBA in that form that is locking the table.

    I just fix it though, it's not pretty but simple and works. I built a query that is dumping the date in another table and I call that table record from a List box, that removed the conflict with the main table. Thanks offering your help.

  6. #6
    geotrouvetout67 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2019
    Posts
    108
    I've been trying to make this "prettier" with a function that runs on load but I'm doing something wrong.

    I set a temp table tblLastRefreshDate with a field [RefreshDateTime]

    The idea is at each load, delete the temp table, select the first date record in the main table "Forecasts" and set that value as variable LastRefresh then insert that variable back into the temporary table

    If I set LastRefresh AS either String or Date, I get the error "Compile Error: Object required with "LastRefresh" highlighted on the "Set" line. If I don't declare the variable as anything, I get a "Type missmatch" error in the last line.

    Code:
    Private Sub RefreshTime()'save last refresh date
    
    DoCmd.SetWarnings False
    
    Dim LastRefresh
    
    
    
    CurrentDb.Execute "DELETE * FROM tblLastRefreshTime"
    
    
    Set LastRefresh = CurrentDb.OpenRecordset("SELECT First([RefreshDate]) FROM Forecasts")
    
    
    CurrentDb.Execute "INSERT INTO tblLastRefreshDate(RefreshDateTime) VALUES ('" & LastRefresh & "')"
    
    
    End Sub

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

Similar Threads

  1. Replies: 2
    Last Post: 04-19-2019, 05:13 PM
  2. Replies: 10
    Last Post: 01-23-2016, 12:29 PM
  3. Replies: 20
    Last Post: 01-13-2015, 02:23 PM
  4. Replies: 6
    Last Post: 06-03-2014, 01:01 PM
  5. Replies: 2
    Last Post: 04-27-2010, 01:25 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