Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,412
    Don't know name of your frmYours.
    I've had something like this work in the past.
    Even though the code is contained in frmYours, you still need to specify it explicitly.
    Code:
    dim dq as string
    dq=chr$(34)     'double quote
    Forms("frmYours").Controls("txtTotalCasesToDate").ControlSource = "=" & dq & DCount("CaseNum", "tblCase") & dq


  2. #17
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,428
    I don't see why you think this would work
    Code:
    Private Sub txtTotalCasesToDate_GotFocus()
    Dim strSQL As String strSQL = "SELECT Count(CaseNum) As CaseCount FROM tblCase " 'strSQL = Nz(DCount("CaseNum", "tblCase"), 0) Me![txtTotalCasesToDate].ControlSource = strSQL 'Me![txtTotalCasesToDate].Requery
    End Sub
    All you are doing is assigning a string (of sql code) to your textbox

    To run sql you need to execute it e.g.

    Code:
    dim rst as dao.recordset
    set rst=currentdb.execute  "SELECT Count(CaseNum) As CaseCount FROM tblCase "
    if not rst.eof then Me![txtTotalCasesToDate]=rst!CaseCount
    set rst=nothing
    rst.close
    not tested but if you changed your textbox to a listbox (one row high) you could use

    Me![lstTotalCasesToDate].RowSource = "SELECT Count(CaseNum) As CaseCount FROM tblCase "

  3. #18
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    211
    Quote Originally Posted by Ajax View Post
    I don't see why you think this would work"
    It was example code explaining different types of things tried for SA of others, so some of it doesn't match up (i.e. the way it shows I know it will present the string in the field). Even still, it doesn't scratch the surface of things I tried. Fact of matter is Access has its corks.

    Setting RowSource will not work because the text box is unbound (I tried by accident trying to type ControlSource ).

  4. #19
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    211
    Quote Originally Posted by davegri View Post
    Don't know name of your frmYours.
    I've had something like this work in the past.
    Even though the code is contained in frmYours, you still need to specify it explicitly.
    Code:
    dim dq as string
    dq=chr$(34)     'double quote
    Forms("frmYours").Controls("txtTotalCasesToDate").ControlSource = "=" & dq & DCount("CaseNum", "tblCase") & dq
    That is interesting...

    Essentially that is what I was trying to do, that is keep calculations contained within forms for ease of management and troubleshooting.

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

Similar Threads

  1. Replies: 22
    Last Post: 01-16-2018, 07:18 AM
  2. Replies: 6
    Last Post: 05-03-2016, 05:21 PM
  3. Unbound text boxes show #ERROR on data entry line
    By GraeagleBill in forum Forms
    Replies: 4
    Last Post: 01-07-2015, 12:44 AM
  4. Force update of unbound calculated control
    By LillMcGill in forum Forms
    Replies: 7
    Last Post: 04-15-2013, 06:51 PM
  5. Replies: 2
    Last Post: 06-11-2012, 09:37 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