Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2006
    Posts
    52

    Unanswered: insert default value in textbox using vba

    Hi, i have a text box called ImagePath
    and want to set the default value to the file: flowerclipart.jpg which exists in the application path.
    I wrote the following code and I got #name? in the textbox
    I used msgbox to see if the path is correct or not, i get the bath correctly, and i am sure the picture exists in that path

    here is my code
    Public Function GetDBPath() As String
    Dim defaultPath As String
    GetDBPath = CurrentProject.Path & "\"
    End Function


    Private Sub Form_Current()
    'Dim ImagePath As TextBox
    Dim defaultPath As String
    On Error Resume Next
    Me![imageFrame].Picture = Me![ImagePath]

    defaultPath = GetDBPath & "flowerclipart.jpg"
    MsgBox (defaultPath)
    ImagePath.DefaultValue = defaultPath
    End Sub


    i used dimImagePath as TextBox but I get nothing written in the text box as if there is no default value altough the messagebox shows the correct path

    I just want the ImagePath text both to show the correct path of flowerclipart.jpg and update the image to the related frame WHEN I GO TO A NEW BLANK RECORD
    I mean if i already saved default path, i have no problem, ImagePath has the correct path of the related picture, but if i go to a new record, i do not get flowerclipart.jpg (the default path), altough the message shows the correct path

    hope you understand me

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Try:
    Code:
    ImagePath.DefaultValue = Chr(34) & defaultPath & Chr(34)
    Have a nice day!

  3. #3
    Join Date
    Aug 2006
    Posts
    52
    Hi, it is still not working, still not showing the default picture

    Private Sub Form_Current()
    Dim defaultPath As String
    On Error Resume Next
    Me![imageFrame].Picture = Me![txtImagePath]

    defaultPath = GetDBPath & "flowerclipart.jpg"
    MsgBox (defaultPath)
    txtImagePath.DefaultValue = Chr(34) & defaultPath & Chr(34)
    Me![imageFrame].Picture = Me![txtImagePath]


    End Sub

    do i need to use if statement? i tried this but still not working, do i need to put it somewhere else? currently it is in the Private Sub Form_Current()

    If txtImagePath.text = Null Then
    txtImagePath.text = Chr(34) & defaultPath & Chr(34)
    Me![imageFrame].Picture = Me![txtImagePath]
    Me.refresh
    Else
    Me![imageFrame].Picture = Me![txtImagePath]
    End If

    it is still not showing the default picture when it is null

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Quote Originally Posted by oakeyes View Post
    Hi, it is still not working, still not showing the default picture

    Private Sub Form_Current()
    Dim defaultPath As String
    On Error Resume Next
    Me![imageFrame].Picture = Me![txtImagePath]

    defaultPath = GetDBPath & "flowerclipart.jpg"
    MsgBox (defaultPath)
    txtImagePath.DefaultValue = Chr(34) & defaultPath & Chr(34)
    Me![imageFrame].Picture = Me![txtImagePath]


    End Sub

    do i need to use if statement? i tried this but still not working, do i need to put it somewhere else? currently it is in the Private Sub Form_Current()

    If txtImagePath.text = Null Then
    txtImagePath.text = Chr(34) & defaultPath & Chr(34)
    Me![imageFrame].Picture = Me![txtImagePath]
    Me.refresh
    Else
    Me![imageFrame].Picture = Me![txtImagePath]
    End If

    it is still not showing the default picture when it is null
    This cannot work. Use:
    Code:
    Me.imageFrame.Picture = IIf(IsNull(Me.txtImagePath.Value) = True, GetDBPath & "flowerclipart.jpg", Me.txtImagePath.Value)
    Have a nice day!

  5. #5
    Join Date
    Aug 2006
    Posts
    52

    Thanks

    Thank you so so much, it works greatly now,

  6. #6
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

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