Results 1 to 13 of 13
  1. #1
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186

    Using OpenArg applied to a subform

    Hello everyone,



    I have a question how to apply the OpenArg to a subform

    I have an application to change the languague depending on the user decision. All works good! however when in the subform there is not working, maybe I have something wrong in the syntaxis of the code

    I highly appreciate the help! =)

    Code:
    Private Sub Form_Open(Cancel As Integer)
    
    
    MainForm_Frm.IDCostlbl.Caption = DLookup("[" & Me.OpenArgs & "]", "[Language_tbl]", "[label]='IDCostlbl'")
    MainForm_Frm.NoPartCostolbl.Caption = DLookup("[" & Me.OpenArgs & "]", "[Language_tbl]", "[label]='NoPartCostolbl'")
    MainForm_Frm.DesCostNPlbl.Caption = DLookup("[" & Me.OpenArgs & "]", "[Language_tbl]", "[label]='DesCostNPlbl'")
    
    End Sub

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    You would need to refer to the OpenArgs of the parent form I would have thought?

    Also what does OpenArgs actually contain?

    However subforms open before main form, so you would need to delay the caption settings.

    Perhaps have a sub in the subform that is called from the mainform (or in the mainform) to set all the control captions to the correct language?
    Might be quicker to retrieve all the records with a recordset, then walk the controls setting the captions? For that you would need the control name in the language record.
    You can hide the subform initially and display when captions have been changed.
    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

  3. #3
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186
    My OpenArgs contains a number of identification of the language chosen by the user
    Example: 1 = Spanish, 2 = English, 3 = German and 4 = French

    Internally there is a none visible field named Languagetxt which is a text box and contains this number which is used to change all the labels to the language
    Everything works good but not the subform

    The code that opens the main form is this:

    Code:
    Private Sub NCcmd_Click()
    
    Dim stDocName As String
    stDocName = "MainNC_Frm"
    DoCmd.OpenForm stDocName, , , , , , Me.languagetxt
    
    End Sub
    How would be stated this recommendation?
    "so you would need to delay the caption settings."

    Thanks in advance for the help!!


  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    As I said, the subform opens before the mainform?
    Perhaps setup a function and pass in the form object and language?
    Then that function processes all the controls in a form, be it mainform or subform?

    I would have a recordset for the form and each control with their relevant language text, then loop through the recordset and set the control from the recordset data.
    Alternatively hide the subform until the mainform loads and the labels have been changed.

    This is all theory, as I have never had to do it myself, but that would be the way I would approach it, unless someone had a better idea.

    Another member here, twgonder, is playing with various languages. You might want to PM him and ask how he is managing, if he is, that is.
    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
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Is this a continuation of this thread?

    https://www.accessforums.net/showthread.php?t=88735

    It should be possible to loop through the controls collection, including the subform.

    I think the class I did in the other thread may work if you instantiate the class in the subform as well. I haven't tried it but will when I get home.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Fairly certain you can create custom properties for a form. I just can't recall at the moment if they persist once the form is closed. Just thought it might be an option worth exploring.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    I confirmed that the class I did in the other thread works in a subform too.

    Just instantiate the class in the main form and the subform.
    Attached Files Attached Files
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  8. #8
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    Quote Originally Posted by moke123 View Post
    I confirmed that the class I did in the other thread works in a subform too.

    Just instantiate the class in the main form and the subform.
    Thanks Moke Micron solved my problem

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    Quote Originally Posted by moke123 View Post
    I confirmed that the class I did in the other thread works in a subform too.

    Just instantiate the class in the main form and the subform.
    Neatly done Moke.
    I was thinking a record for each language and label.
    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

  10. #10
    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 Welshgasman View Post
    Neatly done Moke.
    I was thinking a record for each language and label.
    Thanks GMan.

    I'll have to finish the app I started after getting carried away with the other thread.

    My table consists of the label name as the PK and then a field for each language. To add a language you just add a field and supply the text for each label. The app will handle up to 8 languages.

    It seemed to me that it would be a real P.I.T.A. to enter all the label names for each form so I automated the import, as well as renaming of the labels so they are easily identified in the table (ie. a label attached to a textbox with a control source of FirstName will be renamed to lblFirstName.) There is also a form to enter the text for each label and language.
    Click image for larger version. 

Name:	Screenshot 2023-10-20 081011.jpg 
Views:	19 
Size:	58.5 KB 
ID:	50918
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  11. #11
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I confirmed that the class I did in the other thread works in a subform too.
    I'm saying you can do it without a class. Maybe you are too but I don't know. What I'm referring to I picked up at Access World Forums; probably from MajP.
    IIRC, it just involves appending a custom property to the properties collection of a form and only has to run once. Same method as adding shift key bypass property to a db, which I imagine you've done before.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  12. #12
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    It seemed to me that it would be a real P.I.T.A. to enter all the label names for each form
    The method I use is to store the caption, then lookup the caption against a translation table

    tblLanguages
    LanguagePK...LanguageName
    1..................English
    2..................Spanish
    3..................German
    etc (athough I actually use the microsoft language ID's

    tblCaptions
    CaptionPK...CaptionText (note caption text should be indexed unique to avoid duplicates)
    1...............Customer
    2...............Supplier
    3...............Customer Name

    tblTranslate
    CaptionPK.....IanguageFK....Translation
    1.................2..................Cliente
    1..........................3...................... ....Kunde
    3..........................3...................... ....Name des Kunden

    etc

    easy enough then to to loop through the form controls and where a control has a caption, to change it. In the form open event


    Code:
    dim ctl as control
    Code:
    on error resume next 'to ignore controls without a caption property
    for each ctl in me,controls
         ctl.caption=nz(dlookup("Translation","qryTranslation","CaptionText='" & ctl.caption & "'"), ctl.caption)
    next ctl
    
    The nz is to not translate captions that do not have a translation

    I use a tempvar to supply the language of choice - populated at login from a user table

    So qryTranslation looks like this

    Code:
    SELECT CaptionText, Translation
    FROM tblCaptions INNER JOIN tblTranslate ON
    Code:
    tblCaptions.CaptionPK = tblTranslate.CaptionFK
    WHERE languageFK=tempVars!UserLanguage
    
    Main benefit is a shorter list of translations to maintain since 'Customer' may appear in many forms

    Other benefits - you can loop through the forms and using similar code to the above populate the captions table. Similar code can also be used to add new captions and identify ones no longer used

    And once you have your list of captions, you can use code to get the translations from microsoft, google or similar (plenty of free services about)

  13. #13
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    And once you have your list of captions, you can use code to get the translations from microsoft, google or similar (plenty of free services about)
    That was something I didn't consider until reading your post. Never thought it would be that easy or free. I just spent 2 days in a marathon tinkering session writing an app I really don't have any use for.
    Chalk it up as an educational exercise.

    The translation part was pretty easy. I can't vouch for the accuracy but it looked good to me. I even slowed it down because I was afraid of slamming the server with a 100's of requests at once.

    I've got some ideas where to use it elsewhere so it looks like another late night.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

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

Similar Threads

  1. Replies: 1
    Last Post: 05-06-2019, 10:27 AM
  2. Replies: 5
    Last Post: 12-11-2018, 05:52 AM
  3. OpenArg not passing to one report
    By Monterey_Manzer in forum Programming
    Replies: 12
    Last Post: 04-15-2014, 12:59 PM
  4. OpenArg help.
    By manic in forum Forms
    Replies: 4
    Last Post: 10-13-2012, 09:20 AM
  5. passing openArg to a listbox on other form
    By focosi in forum Access
    Replies: 7
    Last Post: 08-12-2011, 04:27 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