Results 1 to 6 of 6
  1. #1
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568

    Pass textbox object into form

    Hi,



    I am using Allan Brownie Calendar for showing dates.

    I added code:

    Code:
    Public gtxtCalTarget As TextBox 'Text box to return the date from the calendar to.
    
    
    Public Function CalendarFor(txt As TextBox)
    On Error GoTo Err_Handler
        'Purpose:   Open the calendar form, identifying the text box to return the date to.
        'Arguments: txt = the text box to return the date to.
        '           strTitle = the caption for the calendar form (passed in OpenArgs).
        
        Set gtxtCalTarget = txt
       
        DoCmd.OpenForm "frmCalendar", windowmode:=acDialog
    ''    Form_frmCalendar.Tag = gtxtCalTarget
        
    Exit_Handler:
        Exit Function
    
    
    Err_Handler:
        MsgBox "Error " & Err.Number & " - " & Err.Description, vbExclamation, "CalendarFor()"
        Resume Exit_Handler
    End Function
    I added this function into my textbox on form:
    Click image for larger version. 

Name:	calendar jpg.png 
Views:	23 
Size:	48.7 KB 
ID:	31026

    and now i want to pass public variable gtxtCalTarget into form in order to use it.
    Code is working fine on the beginning but after opening the form public variable is not available within form vba code.

    How can i solve it?
    How can i pass gtxtCalTarget into my form?

    Thank ou for helpping me,
    Best wishes,
    Jacek

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    use the full path ,from outside the form:
    forms!myform!txtBox = gtxtCalTarget

    if in the form at form_load event

    txtbox =
    gtxtCalTarget

  3. #3
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    I use Allen Browne's calendar routine also, however my calendar is a subform on a form, so I don't understand how you are using it? Access has its own calendar for date fields.

  4. #4
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    Hi ranman256.

    Your method is ok to pass string variable.
    What if i want to pass whole object (textbox VBa object)?

    Hi aytee111,

    Yes,

    Access has own calendar but it is not very useful for me. I wanted to have all holidays marked and additionally to have quick possibility to go back for example 10 years earlier.

    Best wishes,
    Jacek

  5. #5
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    make a function to pass the textbox in the parameter...

    usage: Setbox me.txtBox

    Code:
    sub Setbox(ptxtBox as textbox)
       ptxtBox = "my value"   
    end sub

  6. #6
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    thank you ranman256.

    I handled it using code:

    Code:
    Zmienna = Form_tbl_Korekty.Txb_calendar.Value
    
    Set gtxtCalTarget = Forms("tbl_Korekty")(Zmienna)
    
    
    gtxtCalTarget = Me.txtDate
    So Zmienna is txtbox name as string
    Next i am simply setting txtbox gtxtCalTarget as textbox using zmienna as textbox's name,

    Jacek

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

Similar Threads

  1. Replies: 2
    Last Post: 12-10-2012, 02:23 PM
  2. Replies: 5
    Last Post: 04-19-2012, 09:35 AM
  3. SET focus back to TEXTBOX if validation does NOT pass
    By taimysho0 in forum Programming
    Replies: 5
    Last Post: 12-04-2011, 10:10 PM
  4. Display PASS or FAIL using Unbound textbox
    By Shambler2 in forum Reports
    Replies: 7
    Last Post: 06-02-2011, 11:19 AM
  5. Replies: 4
    Last Post: 04-22-2011, 03:08 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