Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186

    Take the value from an unbound field

    Hello everyone,
    I have a form with one unbound textbox field named "languagetxt" where the values it can take are 1, 2, 3 and 4. It works good an according to the language chosen it takes such numbers, it works to change the language to my labels



    The issue I have is into the code because when I want to take this value from the unbound texbox field it says it is Null, I don't know how to fix it, i highly apprecitate the help!!

    Code:
    Private Sub Form_Open(Cancel As Integer)
    
    
    Dim language As String
    Dim key1 As String
    Dim key2 As String
    Dim Numberx As String
    
    
    key1 = "["
    Number- = Me.languagetxt  'HERE IT'S MY ISSUE BECAUSE IT SAYS THE VALUE IS NULL, I AM NOT SURE HOW TO FIX IT
    key2 = "]"
    language = key1 & Numberx & key2
    
    
    Me.userlbl.Caption = DLookup(language, "[language_tbl]", "[label]= '" & Me.userlbl.Name & "'")
    
    
    End Sub

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    you have

    Dim Numberx As String

    and

    Number- = Me.languagetxt

    make sure you have OPTION EXPLICIT at the top of every module - then you won't make this sort of mistake

    edit:

    you could just use a single line of code

    Me.userlbl.Caption = DLookup("[" & Me.languagetxt & "]", "[language_tbl]", "[label]= '" & Me.userlbl.Name & "'")

  3. #3
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    When is the textbox populated? Your running this code on Open. If it's unbound where/ when is it getting input?
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  4. #4
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186
    Hi
    Correcting a little my mistake I have

    Dim NumberX As String
    NumberX = Me.languagetxt 'The unbound textbox

    I have at the top of the module this lines

    Option Compare Database
    Option Explicit

    Much better idea this edition:
    Me.userlbl.Caption = DLookup("[" & Me.languagetxt & "]", "[language_tbl]", "[label]= '" & Me.userlbl.Name & "'")

    but this is still showing the same issue

  5. #5
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186
    Hi!
    This is populated on event "On Open"

    It takes the value from a previous form named Languagesetting_Frm which has into a droplistbox with the language (English, Spanish, German and French), this data comes from a table named language with the fields "ID" and "language" into the same form I have also an unbound textbox named "languagetxt" that get the "ID" number of the language and finally a command button named "Startcmd"

    Code:
    Private Sub Startcmd_Click()
    
    
    Dim stDocName As String
    Dim stLinkCriteria As String
    
    
    stDocName = "Login_Frm"
    
    
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    Forms![Login_Frm]!languagetxt = Me.languagetxt  'Both forms has the same name to make easy to me
    
    
    End Sub
    Once the user click on the command button it opens the form login_frm and the idea is showing the labels on the previous language chosen.

  6. #6
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    but this is still showing the same issue
    see post 3 - at the form open event, your unbound control will not be populated - and won't be until the user enters something, which can't happen until after the form current event has fired.

    For testing purposes, suggest use the languagetxt after update event

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Fields in table are named 1, 2, 3, 4?

    Answer moke123 question in post 3: When and how does this textbox get a value?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186
    Hi CJ_London
    As you suggested I made the trial with an event After update and it works changing the info of the labels! =)
    What do you suggest that it could happen since the load or the open of the form?

  9. #9
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186
    Hi June7
    Yes exactaly the table language_tbl has this fields:
    "ID" (values: 1,2,3 and 4), "label" (name of the labels into the form), "1" "2", "3" and "4"
    (information of every label in the different language)

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    If user is selecting language on Languagesetting_Frm and you need to pass that choice to another form when it is opened, several ways to do that.

    1. OpenArgs of DoCmd.OpenForm

    2. set a global variable or TempVar that can be used anywhere

    3. first form sets value of control on second form

    4. second form references control on first form (if it remains open).
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Quote Originally Posted by June7 View Post
    If user is selecting language on Languagesetting_Frm and you need to pass that choice to another form when it is opened, several ways to do that.

    1. OpenArgs of DoCmd.OpenForm

    2. set a global variable or TempVar that can be used anywhere

    3. first form sets value of control on second form

    4. second form references control on first form (if it remains open).
    5. Hidden form that stays open but hidden
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  12. #12
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Could also just use the Text property of the control instead of its value?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  13. #13
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186
    Hi June_7 and moke123

    Do you have any example about the suggestions?
    I like so much the idea of the "set a global variable" I think the others ideas are also good but maybe are not so clear to me how to establish them

  14. #14
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186
    Hi Micron
    How should I do this? I highly appreciate the help
    With this new application I am doing I am learning so much =)

  15. #15
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    As in
    Me.languagetxt.SetFocus
    TextNumberX = Me.languagetxt.Text

    Untested, so not sure. When you don't use .Text you use the default of .Value instead. As pointed out, at the time your code runs the control has no value so don't continue to use the form open event if you still are. Also, a control has to have the focus in order to use the .Text property so I added that.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 3
    Last Post: 12-21-2021, 07:44 PM
  2. Replies: 4
    Last Post: 08-04-2020, 12:13 AM
  3. Replies: 3
    Last Post: 11-29-2016, 10:03 AM
  4. Replies: 5
    Last Post: 01-30-2015, 02:45 PM
  5. unbound field
    By slimjen in forum Forms
    Replies: 9
    Last Post: 10-16-2013, 02:22 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