Results 1 to 8 of 8
  1. #1
    lefty2cox is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    May 2013
    Posts
    163

    Recordset stuff

    I have myForm. I'm creating some code to take info from some of the fields on the MyForm and create a new record in a table.

    rs.Fields("myFieldName") = txtMyTextBox.value --- this works
    rs.Fields("myFieldName") = MyTextBox --- this also works (using the controlsource instead of the textboxname.value)



    But I can't get either to work with txtMyCalcBox, which is a text box on the form with a formula as it's control source.

    I did get it to work with:
    Forms!MyForm!txtMyCalcBox

    I'm trying to understand why.

    Thanks.

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    It might work with rs.Fields("myFieldName") = .txtMyTextBox but I'd never not use Me as a qualifier, so
    rs.Fields("myfieldName") = Me.txtMyTextbox

    You have the additional circumstance where one is bound but the other (the one with the expression in the control source) is not. In any event, I'm surprised that either of the first 2 worked at all if that's how it was really written.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,857
    Value is the default property of controls, so when you know that, you tend to not use it.

    That mucks you up when you use TempVars, as then you do need to use the .Value property. :-)
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    lefty2cox is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    May 2013
    Posts
    163
    Got it. Thank you all.

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    Code:
    That mucks you up when you use TempVars, as then you do need to use the .Value property. :-)
    To expound on this a bit more...

    Tempvars!tvTextbox = Me.MyTextBox will error because Access thinks you want to assign an object (the textbox control)

    so you have to be explicit
    Tempvars!tvTextbox = Me.MyTextBox.Value

    any later reference to the tempvar itself doesn't, so

    If Tempvar!tvTextbox = "Hello"

    will work fine.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,857
    No, I'm pretty sure that I have had to use a .Value for a TempVar in some situations, and hence my remembering that issue.?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    Quote Originally Posted by Welshgasman View Post
    No, I'm pretty sure that I have had to use a .Value for a TempVar in some situations, and hence my remembering that issue.?
    I've used 'em by the hundreds since Access 2007, and stand by the statements in post #5.

    Not saying you can't code

    If Tempvars!tvTextBox.Value = "Hello"

    I don't do it that way and have never had a problem that I remember.

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,857
    In queries perhaps?
    I'm not going to get into an argument about it, and if I find the actual issue, I dare say I will have forgotten this thread by then. as I do not use Access much at all and rely on when I used to use it? :-)
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Dates and all that horrible stuff
    By clean32 in forum Programming
    Replies: 8
    Last Post: 06-20-2011, 06:34 PM
  2. Need help figuring out stuff
    By Buakaw in forum Access
    Replies: 3
    Last Post: 01-31-2011, 02:59 AM
  3. Simple stuff
    By gdemets in forum Queries
    Replies: 5
    Last Post: 12-09-2010, 09:25 AM
  4. Access Simple Stuff, help
    By clwclw in forum Access
    Replies: 1
    Last Post: 05-02-2009, 03:10 PM
  5. I need help with weird stuff happening on a DB
    By makotoshishio in forum Access
    Replies: 9
    Last Post: 04-02-2009, 12:20 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