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

    Unanswered: Passing a txtbox to a Sub

    I would like to ck 2 txtboxes to make sure they contain valid date values. the code will be the same for each so i wanted to write a sub and pass in the txtbox, but my vba is not in a good mood. my code

    Private Sub cmdQry_Click()
    On Error GoTo Err_cmdQry_Click

    Dim txtbox As New TextBox
    txtbox = txtBeg 'txtbeg is name of txt on form
    validateDates (txtbox)



    Private Sub validateDates(txtbox As TextBox)
    With txtbox
    .SetFocus
    If Not IsDate(.Text) Then
    MsgBox "You must enter a valid DATE! ", , "MichaelSoft"
    .SetFocus
    .BackColor = vbYellow
    GoTo Exit_cmdQry_Click:
    End If
    End With
    End Sub


    by the way the exix_cmdQry_click is in another sub. Can i do that???


    ~M

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    gosh ...i did this a few days ago but i forget the details.

    possible suggestion:
    drop the SetFocus AND the .Text
    use .Value
    (cos .Value doesn't need focus - better, use .Value ALWAYS unless you have a specific reason not to want to address boxes not having focus)

    if this doesn't fix it AND if i remember which lump of my code passed a txtbox, i'll get back to you.

    izy

Posting Permissions

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