Results 1 to 11 of 11
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    source of datatype issue?

    In the segments of code below, my intent is to set the name of a textbox control that will receive a string at a later time in processing. I can't find the source of the runtime 13 mismatch.

    I've tried the code with and without the ".Value" and also setting a variant variable to the string with an attempt to assign that variable to the textbox.

    I'm obviously missing something really basic here?



    Code:
    Dim ctrlEMDT As Control
    <snip>
        Set ctrlEMDT = tbDTSample
    <snip>
        Set ctrlEMDT = tbDTAllSubscribers
    <snip>
        Set ctrlEMDT = tbDTAsSelected
    <snip>
        Me.Controls(ctrlEMDT).Value = Date & " (" & Format(Time, "hh:mmampm") & ")"
        Me.Controls(ctrlEMDT).Visible = True

  2. #2
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    What happens if you do this:
    Me.Controls(ctrlEMDT.Name).Value = Date & " (" & Format(Time, "hh:mmampm") & ")"
    Me.Controls(ctrlEMDT.Name).Visible = True
    Please click on the ⭐ below if this post helped you.


  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Where is the error? The lines setting .Value and .Visible might be expecting a string value. Or try

    ctrlEMDT.Value = ...
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    You are using set instead of let?
    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

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Adding the ".Name" as you suggest clears up the issue.
    Thanks, Bill

  6. #6
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Me.Controls(ctrlEMDT).Value = Date & " (" & Format(Time, "hh:mmampm") & ")"
    Post #2 solved the problem, but your suggestion also works:
    Code:
        ctrlEMDT.Value = Date & " (" & Format(Time, "hh:mmampm") & ")"
        ctrlEMDT.Visible = True

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    If I try to use "Let" I get a runtime error 91.

    Code:
    ctrlEMDT = tbDTSample

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    That is the same as Let?, you are just assigning a value to what I believe should be a string?
    Then you use that variable in Me.Controls( )
    Code:
    Me.Controls(ctrlEMDT) = Date & " (" & Format(Time, "hh:mmampm") & ")"
    Edit: Let works fine for me?

    Code:
    Let Me.Controls("txtSteps") = 99
    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

  9. #9
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Code:
    Me.Controls(ctrlEMDT) = Date & " (" & Format(Time, "hh:mmampm") & ")"
    Is what I coded to begin with and got the runtime 13 mismatch.

    Anyway, either of #2 or Paul's suggestion got the job done.

    Thanks,
    Bill

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by GraeagleBill View Post
    Code:
    Me.Controls(ctrlEMDT) = Date & " (" & Format(Time, "hh:mmampm") & ")"
    Is what I coded to begin with and got the runtime 13 mismatch.

    Anyway, either of #2 or Paul's suggestion got the job done.

    Thanks,
    Bill
    That is because ctrlIEMDT is defined as a control and not a string?
    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

  11. #11
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    You wouldn't need the name property if you correctly passed the name as a string: Me.Controls("ctrlIEMDT") or maybe even Me.Controls!ctrlIEMDT because as you know, when you use the bang operator, what follows it is passed as a string to the default property of what precedes it. In this case, that would be .Name
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Setting Control Source Property Issue
    By Sarah11 in forum Forms
    Replies: 2
    Last Post: 09-23-2017, 10:37 PM
  2. Replies: 2
    Last Post: 07-13-2016, 08:28 AM
  3. Text Box Control Source Issue
    By timbit6002 in forum Forms
    Replies: 8
    Last Post: 03-01-2012, 02:03 PM
  4. issue changing datatype in table
    By Gareth Keenan in forum Access
    Replies: 3
    Last Post: 09-27-2011, 02:57 PM
  5. confusing datatype error issue
    By TheShabz in forum Queries
    Replies: 5
    Last Post: 10-11-2010, 05:14 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