Subform setfocus

  • Thread starter gsnidow via AccessMonster.com
  • Start date

G

gsnidow via AccessMonster.com

Greetings folks. I have a form and subform. I am trying to prevent server
messages from popping up, because they confuse users. I want to ensure that
a non-nullable field on the subform is populated before the focus leaves the
subform. I have put the following code behind the exit event of the subform.

Private Sub frmSearchEWOSub_Exit(Cancel As Integer)
On Error GoTo Err_frmSearchEWOSub_Exit

Dim strSQLR As String
strSQLR = "DELETE tblroadblocks " & _
"WHERE r.id = '" & frmSearchEWOSub.Form.txtID & "' " & _
"FROM tblroadblocks r"

If Me.frmSearchEWOSub.SourceObject = "frmSearchEWO_Roadblocks" Then
If Len("" & Me.frmSearchEWOSub.Form.txtroadblock) = 0 Then
If MsgBox("The roadblock description field is blank. This record
will be deleted if there is no description. Do you want to delete this
record?", vbYesNo, "text box") = vbYes Then
MsgBox "enter delete code here", vbOKOnly 'This is where I will
run delete code
Else: Me.frmSearchEWOSub.Form.txtroadblock.SetFocus 'this is what
I can not figure out
End If
End If
End If

Exit_frmSearchEWOSub_Exit:
Exit Sub

Err_frmSearchEWOSub_Exit:
MsgBox Err.Description
Resume Exit_frmSearchEWOSub_Exit
End Sub

everything works except for the line where I am trying to set the focus to
the control I want populated. Any ideas?

Greg Snidow
 
Ad

Advertisements

G

geppo

Ciao said:
Greetings folks. I have a form and subform. I am trying to prevent
server messages from popping up, because they confuse users. I want
to ensure that a non-nullable field on the subform is populated
before the focus leaves the subform. I have put the following code
behind the exit event of the subform.

Private Sub frmSearchEWOSub_Exit(Cancel As Integer)
On Error GoTo Err_frmSearchEWOSub_Exit

Dim strSQLR As String
strSQLR = "DELETE tblroadblocks " & _
"WHERE r.id = '" & frmSearchEWOSub.Form.txtID & "' " & _
"FROM tblroadblocks r"

If Me.frmSearchEWOSub.SourceObject = "frmSearchEWO_Roadblocks" Then
If Len("" & Me.frmSearchEWOSub.Form.txtroadblock) = 0 Then
If MsgBox("The roadblock description field is blank. This
record will be deleted if there is no description. Do you want to
delete this record?", vbYesNo, "text box") = vbYes Then
MsgBox "enter delete code here", vbOKOnly 'This is where I
will run delete code


Else
Me.frmSearchEWOSub.SetFocus
Me.frmSearchEWOSub.Form.txtroadblock.SetFocus 'this
 
Ad

Advertisements

G

gsnidow via AccessMonster.com

Thanks geppo. I got it to work with frmSearchEWOSub.Form.ActiveControl =
txtroadblock
Greetings folks. I have a form and subform. I am trying to prevent
server messages from popping up, because they confuse users. I want
[quoted text clipped - 17 lines]
MsgBox "enter delete code here", vbOKOnly 'This is where I
will run delete code

Else
Me.frmSearchEWOSub.SetFocus
Me.frmSearchEWOSub.Form.txtroadblock.SetFocus 'this
is what I can not figure out
End If
[quoted text clipped - 13 lines]
Greg Snidow
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top