Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SetFocus Problem

Status
Not open for further replies.

Anu26

Programmer
Oct 29, 2003
1
US
Hi everyone...,

I am kind of new to VBA. I am getting this strange error "can't move focus to the control combo2" when i try to setfocus to the combobox.
What i am doing in my code is i have 2 combobox, let's say combo1 and combo2, i have set the Row source property of both of them to fields of my table, what exactly i want is if i select a value from combo1 i want the corresponding value of the field in combo2 and if i select a value from combo2 i want the corresponding value of the field in combo1. Here is my code, and command4 is the save button where i am trying to save the both combo values with some other data back to table. I would appreciate if somebody could help me.

Private Sub Combo0_Exit(Cancel As Integer)
Dim rst As New ADODB.Recordset
Dim cnn As ADODB.Connection

Set cnn = CurrentProject.Connection
rst.Open "Test", cnn, adOpenDynamic, adLockOptimistic, adCmdTable


Do Until rst.EOF

If rst![Value1] = Combo0.Text Then
Combo2.SetFocus
Combo2.Text = rst![Value2]

GoTo Last
Else
rst.MoveNext
End If
Loop
Last:
rst.Close


End Sub

Private Sub Combo2_Exit(Cancel As Integer)
Dim rst As New ADODB.Recordset
Dim cnn As ADODB.Connection

Set cnn = CurrentProject.Connection
rst.Open "Test", cnn, adOpenDynamic, adLockOptimistic, adCmdTable


Do Until rst.EOF

If rst![Value2] = Combo2.Text Then
Combo0.SetFocus
Combo0.Text = rst![Value1]
GoTo Last
Else
rst.MoveNext
End If
Loop
Last:
rst.Close


End Sub

Private Sub Command4_Click()
Dim rst As New ADODB.Recordset
Dim cnn As ADODB.Connection

Set cnn = CurrentProject.Connection
rst.Open "Test", cnn, adOpenDynamic, adLockOptimistic, adCmdTable


rst.AddNew

Combo0.SetFocus
rst![Value1] = Combo0.Text
MsgBox "Value Set for Value1 field"
Command4.SetFocus
Combo2.SetFocus
rst![Value2] = Combo2.Text
rst.Update
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top