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 GET_LV_MODEL_MASTER
Call cmdClear_Click

End Sub
Function GET_LV_MODEL_MASTER()
Me.lvwMasterModel.ListItems.Clear
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

.MoveNext
Loop
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
    Me.txtPartNumber.SetFocus
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()
	'....
	me.Show
	textbox1.SetFocus
	'....
End Sub
commented: Actual Solution to question. Nice. +4

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. :)

Only a pleasure.:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.