Results 1 to 5 of 5
  1. #1
    dcdimon's Avatar
    dcdimon is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Location
    Bradenton, FL
    Posts
    71

    Module producing #Name? error in text box control

    I have the following script in public module. I'm using the system time to enter the shift name (1st, 2nd, or 3rd) into a text box control (ShiftTXT). When I move to new record the ShiftTXT control is either empty or contains the #Name? error.

    If the control is empty, then when I enter something in another control, the #Name? error populates the control. What am I doing wrong? I have another module that evaluates toggle buttons and other control settings and works without a problem.

    Code:
    Option Compare Database
    Option Explicit
    
    
    Public Sub Shift()
    
    
        If Time$() < "07" Then
        
        Screen.ActiveForm.ShiftTXT = "3rd Shift"
        
            ElseIf Time$() > "15" Then
            
            Screen.ActiveForm.ShiftTXT = "2nd Shift"
            
            Else: Screen.ActiveForm.ShiftTXT = "1st Shift"
        
        End If
    
    
    End Sub
    I'm using =Shift() in the default value property option for the ShiftTXT control. Do I have my module script set up incorrectly or is it an issue with my form property? I've used both the SUB and FUNCTION options with the same results-. Screen below to show the error.



    Click image for larger version. 

Name:	Name error pic.jpg 
Views:	20 
Size:	73.0 KB 
ID:	14098

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You're using it to return a value, so it needs to be a function rather than a sub, and it should return the value rather than set a textbox. To use it like you have it you'd have to call it in code.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    dcdimon's Avatar
    dcdimon is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Location
    Bradenton, FL
    Posts
    71
    I don't understand what you mean by "should return the value rather than set a textbox". I get the function aspect - but not this.

    Also, by "call it in code" do you mean I should be using a vb script to fill the control (which is attached to a field in a table, if that matters) or use an expression rather than just the =Shift()?

    DD

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Do you want the value to save to a table? If so, you can't have the control source of =Shift(), it would have to be the field name and you'd have to set the value in code. If you just want to display, then that control source is fine and I'd change the function. The " As String" portion of this is what I mean by returning a value:

    http://www.baldyweb.com/Function.htm

    Along with inside the function you'd have

    YourFunctionName
    = "String to return"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    dcdimon's Avatar
    dcdimon is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Location
    Bradenton, FL
    Posts
    71
    Okay, I set the module as a Function with the 'as String' tag.

    The shiftTXT control, which IS attached to a field in a table, is showing me the shift name (1st shift and now 2nd shift as it's after 3 pm), but only on every other record. I have no other codes attached to this form so I don't know why it's doing that.

    I'm not clear on what you've offered as advice in the last post and the information on the link is too general for my purposes. It's not helping me understand how to do what I need to do. I've been searching on the web and getting some clearer understanding, but I'm still not seeing what I expect to see on my form - the shift type in my shiftTXT control which, in turns populates my table.

    Can you give me some more specific help on why this is not working as expected?

    DD

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

Similar Threads

  1. Module Error in Macro
    By TimMoffy in forum Modules
    Replies: 3
    Last Post: 06-20-2012, 09:52 AM
  2. Replies: 13
    Last Post: 01-11-2012, 09:44 PM
  3. Saving Module Code to Text Files
    By ioMatt in forum Modules
    Replies: 2
    Last Post: 07-02-2011, 08:18 AM
  4. Error in Module
    By Alex Motilal in forum Modules
    Replies: 9
    Last Post: 01-21-2011, 09:21 AM
  5. Control Source for Text Box (#error)
    By km8415 in forum Forms
    Replies: 3
    Last Post: 06-27-2010, 10:45 AM

Tags for this Thread

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