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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Lose Focus on controls on subforms when command button selected

Status
Not open for further replies.

dmuroff

MIS
Aug 15, 2004
143
CA
HI

I have 2 subforms on a main form. All the controls on the subforms are locked and disabled by Default.

I want to have an "Edit" command button on the main form to unlock and enable the controls on the subform.

I have the following code for the cmdEdit:

Code:
Private Sub cmdEdit_Click()
On Error GoTo Err_cmdEdit_Click
Dim C As Variant

If cmdEdit.Caption = "Edit" Then
    For Each C In Me![frmJobPrices].Controls
        If Right(C.Name, 5) = "price" Then
            C.BorderStyle = 1
            C.Locked = False
            C.Enabled = True
        End If
    Next C
    
    For Each C In Me![frmMoreInfo2].Controls
        If Left(C.Name, 6) = "txtmov" Then
            C.BorderStyle = 1
            C.Locked = False
            C.Enabled = True
        End If
    Next C
    Me![frmMoreInfo2]![txtSystemPrice].BorderStyle = 1
    Me![frmMoreInfo2]![txtSystemPrice].Locked = False
    Me![frmMoreInfo2]![txtSystemPrice].Enabled = True
    cmdEdit.Caption = "Submit"
Else
    For Each C In Me![frmJobPrices].Controls
       
        If Right(C.Name, 5) = "price" Then
            C.BorderStyle = 0
            C.Locked = True
            C.Enabled = False
        End If
    Next C

    For Each C In Me![frmMoreInfo2].Controls
        If Left(C.Name, 6) = "txtmov" Then
            C.BorderStyle = 0
            C.Locked = True
            C.Enabled = False
        End If
    Next C
    Me![frmMoreInfo2]![txtSystemPrice].BorderStyle = 0
    Me![frmMoreInfo2]![txtSystemPrice].Locked = True
    Me![frmMoreInfo2]![txtSystemPrice].Enabled = False
    cmdEdit.Caption = "Edit"
End If

Exit_cmdEdit_Click:
    Exit Sub

Err_cmdEdit_Click:
    MsgBox Err.Description
    Resume Exit_cmdEdit_Click
    
End Sub

Everything works great except that when a control on either of the subforms has the focus, it is not possible to relock and disable the controls with cmdEdit.

Is there a way to lose focus on these controls when the cmdEdit button is pressed? Thanks!
 
Would making a "dummy" text box be acceptable? Where focus is set to it everytime the cmdedit button is clicked?

 
How are ay dmuroff . . . . .

Yes! Name it (ParkCsr or something)then hide it by making the width/height = 0. Move the focus there [blue]Me!ParkCsr[/blue] on entry to your code . . . .

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top