Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2004
    Posts
    67

    Unanswered: Set TextBox default value with VBA

    I am trying to set a TextBox's default value by using VBA code. Does anyone know how this can be done? I have tried the following:

    Dim txtText1 As TextBox
    Dim Val As Double
    Set txtText1 = Forms!frmForm1.txtText1
    Val = InputBox("Enter Value ", , 1.34)
    txtText1.DefaultValue = Val

    I have not entered anything for txtText1's "Default Value" property since I am trying to set the Default Value Property using the above VBA code. The above sets txtText1's value = whatever is entered in the InputBox, but the default value property for txtText1 remains blank.

    Thanks much for any help.

    Jim

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713

    Re: Set TextBox default value with VBA

    Originally posted by jpgalasso
    I am trying to set a TextBox's default value by using VBA code. Does anyone know how this can be done? I have tried the following:

    Dim txtText1 As TextBox
    Dim Val As Double
    Set txtText1 = Forms!frmForm1.txtText1
    Val = InputBox("Enter Value ", , 1.34)
    txtText1.DefaultValue = Val

    I have not entered anything for txtText1's "Default Value" property since I am trying to set the Default Value Property using the above VBA code. The above sets txtText1's value = whatever is entered in the InputBox, but the default value property for txtText1 remains blank.

    Thanks much for any help.

    Jim
    Jim,

    Are you really looking for a value to appear as a default in the textbox when the form appears? If so, do something like:

    TextBox1.Value="Some string here ..."

  3. #3
    Join Date
    Feb 2004
    Posts
    67

    Re: Set TextBox default value with VBA

    Originally posted by M Owen
    Jim,

    Are you really looking for a value to appear as a default in the textbox when the form appears? If so, do something like:

    TextBox1.Value="Some string here ..."
    Thank you for the response, but no, I am not looking to put something in the textbox. I am trying to set the default property of the textbox equal to a constant (i.e. the default value that you usually set in "Design Mode", but that I am trying to set using VBA).

    Any suggestions?

    Thanks again.

    Jim

  4. #4
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713

    Re: Set TextBox default value with VBA

    Originally posted by jpgalasso
    Thank you for the response, but no, I am not looking to put something in the textbox. I am trying to set the default property of the textbox equal to a constant (i.e. the default value that you usually set in "Design Mode", but that I am trying to set using VBA).

    Any suggestions?

    Thanks again.

    Jim
    Well per the DefaultValue help:

    Specifies a String value that is automatically entered in a field when a new record is created.

    So you can set this programmatically ... It does you no good tho unless you create a new record ... You can accomplish the exact same thing with code from my previous posting ... Question: WHY do you need/want to do this? To what purpose?

  5. #5
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Private Sub Form_Open(Cancel As Integer)
    Dim bb As String
    bb = InputBox("Input", "Input", 3)
    Text0.DefaultValue = Val(bb)
    End Sub

  6. #6
    Join Date
    Feb 2004
    Posts
    67

    Re: Set TextBox default value with VBA

    Originally posted by M Owen
    Well per the DefaultValue help:

    Specifies a String value that is automatically entered in a field when a new record is created.

    So you can set this programmatically ... It does you no good tho unless you create a new record ... You can accomplish the exact same thing with code from my previous posting ... Question: WHY do you need/want to do this? To what purpose?

    I need to place a factor on a form that is used in a formula. The factor is only updated once per year. I am trying to give the User the capability of updating the factor by clicking on a command button. Otherwise, I want to keep the textbox that contains the factor locked but viewable.

    Hope this makes some sense.

    Jim

Posting Permissions

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