Hi guys,
I have a very simple form with 2 textboxes only and a listview to display added record. Upon form load i wanted to sest focus to textbox1, but it shows this error:
Run-time error 5:Invalid Procedure call or argument

My form load code

Private Sub Form_Load()
bModelMaster = False
Call cmdClear_Click

End Sub
Dim lItem As ListItem
Dim rs As New ADODB.Recordset
Dim sql As String

Call ConnectDB
sql = "Select * from MODEL_MASTER"
If search = True Then
sql = sql & " where PARTNUMBER like '%" & Me.txtPartNumber.Text & "%'"
End If
rs.Open sql, DB, adOpenStatic, adLockReadOnly

With rs
Do While Not .EOF
Set lItem = Me.lvwMasterModel.ListItems.Add
lItem.SubItems(1) = rs!model_name
lItem.SubItems(2) = rs!PartNumber

End With
search = False

End Function
Private Sub cmdClear_Click()
Dim Ctl As Control
    'Clear all the TextBoxes on the form
    For Each Ctl In Controls
        If TypeOf Ctl Is TextBox Then Ctl.Text = ""
    Next Ctl
End Sub

Please anyone help me. It's urgent :S

Shena, I believe that the form must be fully shown for the SetFocus command of any of that form's children to work. Placing "Me.Show" in your Form_Load() on a line above your textbox1.SetFocus ought to clear that up.

Private Sub Form_Load()
End Sub
Actual Solution to question. Nice.

As Robert pointed out, you can only set focus o something that is visible. If your form is visible, make sure that the textbox is visible as well.

Hi guys,

Thanks a lot for the explanations. I got the work flow now. :)

This question has already been answered. Start a new discussion instead.