Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2003
    Posts
    233

    Unanswered: asign string value to txtbox in form open event

    I have a report with a txtRptParams, i would like to display a string built up in my vba code :
    Me.txtCustomReportParamaters.text= myString

    but im getting an error msg:"You cant reference a property or method for a control unless the control has the focus.

    i also tried
    Me.txtCustomReportParamaters.value= myString
    Me.txtCustomReportParamaters= myString

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    Based off your post title ("...form open event"):

    You are getting this Error because Text is a TextBox property and the only way you can Read or Write to this property is to ensure that the TextBox in question has Focus. It doesn't matter what event or code routine you are trying to access this property from, you will always get this Error if the TextBox does not have Focus. If the TextBox has Focus before you read from or write to this property then all will be fine.

    If you want to actually apply your string contents to the Text property then your code should look like this:

    Me.txtCustomReportParamaters.SetFocus
    Me.txtCustomReportParamaters.Text = myString


    I personally very rarely use the Text property unless I am changing the contents of a TextBox which is bound to a table field which is not yet in view such as would be the case within the OnOpen event. I find it much easier to read and write to a TextBox by simply doing:

    Me.txtCustomReportParamaters = myString

    Mind you, from the OnOpen event this will work fine unless the txtCustomReportParamaters TextBox is bound to a Table field.

    You have shown in your post that you tried this method which indicates this did not work (you should have gotten a different Error) which therefore tells me that the txtCustomReportParamaters TextBox is bound To a Table field. If the txtCustomReportParamaters is bound to a Table field then you would have to wait until the Form is in view before using this method. Therefore....you can not use the above method within the OnOpen event for a bound TextBox. You can however use:

    Me.txtCustomReportParamaters.SetFocus
    Me.txtCustomReportParamaters.Text = myString


    on a bound TextBox from the OnOpen event.

    Now...in your post, you also mention "report". If you are attempting this sort of thing through the OnOpen event of a Report then you will again encounter Errors. Neither method will work. First off...there is no SetFocus for a Report Control so forget about using the Text property. If the TextBox is bound then you're out of luck. If it is not bound, you're still out of luck, from within the OnOpen event anyway.

    You will need to make the TextBox content change from within another event. The Activate event works fine for this using the:

    Me.txtCustomReportParamaters = myString

    method. You can also do this from the OnFormat event for any report Headers.

    .
    Environment:
    Self Taught In ALL Environments.....And It Shows!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •