Code Works for cmdButton Not for Label

J

JamesJ

I'm replacing my command buttons with labels for cosmetic reasons.
The following validation code works for the command button but not for the
label. When I click the label form closes no matter which MsgBox button I
click.
The following code was copied and pasted from the command button to the
label.

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf & _
"Do you want to continue editing the record?", vbExclamation
+ vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

Any help will be appreciated.
James
 
K

Ken Snell [MVP]

The code looks fine. Thus, there must be some other stuff going on in the
code. Post all the code that is in the form's module (if not 1000s of lines
long); what is the name of the label control?
 
J

JamesJ

The label name is lblClose
Here goes..

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

'Disable Pg-up and Pg-down keys

Select Case KeyCode
Case 33, 34, 18
KeyCode = 0
Case Else
End Select

End Sub
*************************************
Private Sub Form_Load()

'Turn the MouseWheel Off

Dim blRet As Boolean
blRet = MouseWheelOFF

End Sub
**************************
Private Sub Form_Open(Cancel As Integer)

Me.RecordSource = Forms!frmContacts.RecordSource

Dim rs As DAO.Recordset

If Not IsNull(Me.OpenArgs) Then
Set rs = Me.RecordsetClone
rs.FindFirst "[ContactID]=" & Me.OpenArgs
If rs.NoMatch Then

Else

Me.Bookmark = rs.Bookmark

End If
End If

End Sub
**********************************
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf & _
"Do you want to continue editing the record?", vbExclamation +
vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Me.Requery

Else

Me!ContactTypeID.SetFocus

End If
End If

End Sub
*****************************************
Private Sub Form_Close()

Forms!frmContacts.Requery
Forms!frmContacts!lstContacts.Requery
Forms!frmContacts!lstContacts.Selected(0) = True

End Sub

'***************************************
Private Sub lblClose_Click()

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf & _
"Do you want to continue editing the record?", vbExclamation
+ vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

End Sub
***************************************
Private Sub lblNew_Click()

DoCmd.GoToRecord , , acNewRec
Me!Listing.SetFocus

End Sub

Private Sub PhoneNumber_Click()

Me!PhoneNumber.SelStart = 0

End Sub
***********************************************************************
Private Sub ContactTypeID_NotInList(NewData As String, Response As Integer)

Dim strSql As String
Dim i As Integer
Dim Msg As String

If Response = acDataErrContinue Then Exit Sub

Msg = "'" & NewData & "' is not currently in the list." & vbCr & vbCr
Msg = Msg & "Please make a selection that is in the list."

i = MsgBox(Msg, vbInformation + vbOKOnly, "Not In List")

Response = acDataErrContinue

End Sub
 
K

Ken Snell [MVP]

Hmmm.... nothing looks suspicious here...

You say you do get the message box to show, but the form closes if you click
Yes button and if you click No button?

Put a breakpoint on the code at the "If Response = vbNo Then" line in the
lblClose_Click event. Let's see what the value of Response is at that point.

I also note that the "same" code is in the form's BeforeUpdate event...
while I wouldn't expect this event to occur prior to the label's Click
event, might be a good experiment to put a breakpoint in that code to see if
it runs before your label's Click event does.

--

Ken Snell
<MS ACCESS MVP>

JamesJ said:
The label name is lblClose
Here goes..

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

'Disable Pg-up and Pg-down keys

Select Case KeyCode
Case 33, 34, 18
KeyCode = 0
Case Else
End Select

End Sub
*************************************
Private Sub Form_Load()

'Turn the MouseWheel Off

Dim blRet As Boolean
blRet = MouseWheelOFF

End Sub
**************************
Private Sub Form_Open(Cancel As Integer)

Me.RecordSource = Forms!frmContacts.RecordSource

Dim rs As DAO.Recordset

If Not IsNull(Me.OpenArgs) Then
Set rs = Me.RecordsetClone
rs.FindFirst "[ContactID]=" & Me.OpenArgs
If rs.NoMatch Then

Else

Me.Bookmark = rs.Bookmark

End If
End If

End Sub
**********************************
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf & _
"Do you want to continue editing the record?", vbExclamation
+ vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Me.Requery

Else

Me!ContactTypeID.SetFocus

End If
End If

End Sub
*****************************************
Private Sub Form_Close()

Forms!frmContacts.Requery
Forms!frmContacts!lstContacts.Requery
Forms!frmContacts!lstContacts.Selected(0) = True

End Sub

'***************************************
Private Sub lblClose_Click()

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf & _
"Do you want to continue editing the record?", vbExclamation
+ vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

End Sub
***************************************
Private Sub lblNew_Click()

DoCmd.GoToRecord , , acNewRec
Me!Listing.SetFocus

End Sub

Private Sub PhoneNumber_Click()

Me!PhoneNumber.SelStart = 0

End Sub
***********************************************************************
Private Sub ContactTypeID_NotInList(NewData As String, Response As
Integer)

Dim strSql As String
Dim i As Integer
Dim Msg As String

If Response = acDataErrContinue Then Exit Sub

Msg = "'" & NewData & "' is not currently in the list." & vbCr & vbCr
Msg = Msg & "Please make a selection that is in the list."

i = MsgBox(Msg, vbInformation + vbOKOnly, "Not In List")

Response = acDataErrContinue

End Sub


Ken Snell said:
The code looks fine. Thus, there must be some other stuff going on in the
code. Post all the code that is in the form's module (if not 1000s of
lines long); what is the name of the label control?
 
J

JamesJ

I set a breakpoint at the line but I'm not sure how to view
the value that is returned.

James

Ken Snell said:
Hmmm.... nothing looks suspicious here...

You say you do get the message box to show, but the form closes if you
click Yes button and if you click No button?

Put a breakpoint on the code at the "If Response = vbNo Then" line in the
lblClose_Click event. Let's see what the value of Response is at that
point.

I also note that the "same" code is in the form's BeforeUpdate event...
while I wouldn't expect this event to occur prior to the label's Click
event, might be a good experiment to put a breakpoint in that code to see
if it runs before your label's Click event does.

--

Ken Snell
<MS ACCESS MVP>

JamesJ said:
The label name is lblClose
Here goes..

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

'Disable Pg-up and Pg-down keys

Select Case KeyCode
Case 33, 34, 18
KeyCode = 0
Case Else
End Select

End Sub
*************************************
Private Sub Form_Load()

'Turn the MouseWheel Off

Dim blRet As Boolean
blRet = MouseWheelOFF

End Sub
**************************
Private Sub Form_Open(Cancel As Integer)

Me.RecordSource = Forms!frmContacts.RecordSource

Dim rs As DAO.Recordset

If Not IsNull(Me.OpenArgs) Then
Set rs = Me.RecordsetClone
rs.FindFirst "[ContactID]=" & Me.OpenArgs
If rs.NoMatch Then

Else

Me.Bookmark = rs.Bookmark

End If
End If

End Sub
**********************************
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf & _
"Do you want to continue editing the record?", vbExclamation
+ vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Me.Requery

Else

Me!ContactTypeID.SetFocus

End If
End If

End Sub
*****************************************
Private Sub Form_Close()

Forms!frmContacts.Requery
Forms!frmContacts!lstContacts.Requery
Forms!frmContacts!lstContacts.Selected(0) = True

End Sub

'***************************************
Private Sub lblClose_Click()

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

End Sub
***************************************
Private Sub lblNew_Click()

DoCmd.GoToRecord , , acNewRec
Me!Listing.SetFocus

End Sub

Private Sub PhoneNumber_Click()

Me!PhoneNumber.SelStart = 0

End Sub
***********************************************************************
Private Sub ContactTypeID_NotInList(NewData As String, Response As
Integer)

Dim strSql As String
Dim i As Integer
Dim Msg As String

If Response = acDataErrContinue Then Exit Sub

Msg = "'" & NewData & "' is not currently in the list." & vbCr & vbCr
Msg = Msg & "Please make a selection that is in the list."

i = MsgBox(Msg, vbInformation + vbOKOnly, "Not In List")

Response = acDataErrContinue

End Sub


Ken Snell said:
The code looks fine. Thus, there must be some other stuff going on in
the code. Post all the code that is in the form's module (if not 1000s
of lines long); what is the name of the label control?

--

Ken Snell
<MS ACCESS MVP>

I'm replacing my command buttons with labels for cosmetic reasons.
The following validation code works for the command button but not for
the
label. When I click the label form closes no matter which MsgBox button
I click.
The following code was copied and pasted from the command button to the
label.

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

Any help will be appreciated.
James
 
K

Ken Snell [MVP]

Sorry... hover the cursor over the variable in the code.. a "popup" text
will show the value.

JamesJ said:
I set a breakpoint at the line but I'm not sure how to view
the value that is returned.

James

Ken Snell said:
Hmmm.... nothing looks suspicious here...

You say you do get the message box to show, but the form closes if you
click Yes button and if you click No button?

Put a breakpoint on the code at the "If Response = vbNo Then" line in the
lblClose_Click event. Let's see what the value of Response is at that
point.

I also note that the "same" code is in the form's BeforeUpdate event...
while I wouldn't expect this event to occur prior to the label's Click
event, might be a good experiment to put a breakpoint in that code to see
if it runs before your label's Click event does.

--

Ken Snell
<MS ACCESS MVP>

JamesJ said:
The label name is lblClose
Here goes..

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

'Disable Pg-up and Pg-down keys

Select Case KeyCode
Case 33, 34, 18
KeyCode = 0
Case Else
End Select

End Sub
*************************************
Private Sub Form_Load()

'Turn the MouseWheel Off

Dim blRet As Boolean
blRet = MouseWheelOFF

End Sub
**************************
Private Sub Form_Open(Cancel As Integer)

Me.RecordSource = Forms!frmContacts.RecordSource

Dim rs As DAO.Recordset

If Not IsNull(Me.OpenArgs) Then
Set rs = Me.RecordsetClone
rs.FindFirst "[ContactID]=" & Me.OpenArgs
If rs.NoMatch Then

Else

Me.Bookmark = rs.Bookmark

End If
End If

End Sub
**********************************
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Me.Requery

Else

Me!ContactTypeID.SetFocus

End If
End If

End Sub
*****************************************
Private Sub Form_Close()

Forms!frmContacts.Requery
Forms!frmContacts!lstContacts.Requery
Forms!frmContacts!lstContacts.Selected(0) = True

End Sub

'***************************************
Private Sub lblClose_Click()

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

End Sub
***************************************
Private Sub lblNew_Click()

DoCmd.GoToRecord , , acNewRec
Me!Listing.SetFocus

End Sub

Private Sub PhoneNumber_Click()

Me!PhoneNumber.SelStart = 0

End Sub
***********************************************************************
Private Sub ContactTypeID_NotInList(NewData As String, Response As
Integer)

Dim strSql As String
Dim i As Integer
Dim Msg As String

If Response = acDataErrContinue Then Exit Sub

Msg = "'" & NewData & "' is not currently in the list." & vbCr & vbCr
Msg = Msg & "Please make a selection that is in the list."

i = MsgBox(Msg, vbInformation + vbOKOnly, "Not In List")

Response = acDataErrContinue

End Sub


The code looks fine. Thus, there must be some other stuff going on in
the code. Post all the code that is in the form's module (if not 1000s
of lines long); what is the name of the label control?

--

Ken Snell
<MS ACCESS MVP>

I'm replacing my command buttons with labels for cosmetic reasons.
The following validation code works for the command button but not for
the
label. When I click the label form closes no matter which MsgBox
button I click.
The following code was copied and pasted from the command button to
the label.

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

Any help will be appreciated.
James
 
J

JamesJ

The program doesn't stop at the breakpoint in the procedure?!
I put a breakpoint in another and it halted?

Ken Snell said:
Sorry... hover the cursor over the variable in the code.. a "popup" text
will show the value.

JamesJ said:
I set a breakpoint at the line but I'm not sure how to view
the value that is returned.

James

Ken Snell said:
Hmmm.... nothing looks suspicious here...

You say you do get the message box to show, but the form closes if you
click Yes button and if you click No button?

Put a breakpoint on the code at the "If Response = vbNo Then" line in
the lblClose_Click event. Let's see what the value of Response is at
that point.

I also note that the "same" code is in the form's BeforeUpdate event...
while I wouldn't expect this event to occur prior to the label's Click
event, might be a good experiment to put a breakpoint in that code to
see if it runs before your label's Click event does.

--

Ken Snell
<MS ACCESS MVP>

The label name is lblClose
Here goes..

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

'Disable Pg-up and Pg-down keys

Select Case KeyCode
Case 33, 34, 18
KeyCode = 0
Case Else
End Select

End Sub
*************************************
Private Sub Form_Load()

'Turn the MouseWheel Off

Dim blRet As Boolean
blRet = MouseWheelOFF

End Sub
**************************
Private Sub Form_Open(Cancel As Integer)

Me.RecordSource = Forms!frmContacts.RecordSource

Dim rs As DAO.Recordset

If Not IsNull(Me.OpenArgs) Then
Set rs = Me.RecordsetClone
rs.FindFirst "[ContactID]=" & Me.OpenArgs
If rs.NoMatch Then

Else

Me.Bookmark = rs.Bookmark

End If
End If

End Sub
**********************************
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Me.Requery

Else

Me!ContactTypeID.SetFocus

End If
End If

End Sub
*****************************************
Private Sub Form_Close()

Forms!frmContacts.Requery
Forms!frmContacts!lstContacts.Requery
Forms!frmContacts!lstContacts.Selected(0) = True

End Sub

'***************************************
Private Sub lblClose_Click()

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

End Sub
***************************************
Private Sub lblNew_Click()

DoCmd.GoToRecord , , acNewRec
Me!Listing.SetFocus

End Sub

Private Sub PhoneNumber_Click()

Me!PhoneNumber.SelStart = 0

End Sub
***********************************************************************
Private Sub ContactTypeID_NotInList(NewData As String, Response As
Integer)

Dim strSql As String
Dim i As Integer
Dim Msg As String

If Response = acDataErrContinue Then Exit Sub

Msg = "'" & NewData & "' is not currently in the list." & vbCr &
vbCr
Msg = Msg & "Please make a selection that is in the list."

i = MsgBox(Msg, vbInformation + vbOKOnly, "Not In List")

Response = acDataErrContinue

End Sub


The code looks fine. Thus, there must be some other stuff going on in
the code. Post all the code that is in the form's module (if not 1000s
of lines long); what is the name of the label control?

--

Ken Snell
<MS ACCESS MVP>

I'm replacing my command buttons with labels for cosmetic reasons.
The following validation code works for the command button but not
for the
label. When I click the label form closes no matter which MsgBox
button I click.
The following code was copied and pasted from the command button to
the label.

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

Any help will be appreciated.
James
 
K

Ken Snell [MVP]

If the program didn't stop where you expected it to stop, then that
indicates that the code in that part of the program is not being run. Where
did you put the other breakpoint when it stopped? We'll need lots of detail
about this so that we can troubleshoot it with you.

--

Ken Snell
<MS ACCESS MVP>

JamesJ said:
The program doesn't stop at the breakpoint in the procedure?!
I put a breakpoint in another and it halted?

Ken Snell said:
Sorry... hover the cursor over the variable in the code.. a "popup" text
will show the value.

JamesJ said:
I set a breakpoint at the line but I'm not sure how to view
the value that is returned.

James

Hmmm.... nothing looks suspicious here...

You say you do get the message box to show, but the form closes if you
click Yes button and if you click No button?

Put a breakpoint on the code at the "If Response = vbNo Then" line in
the lblClose_Click event. Let's see what the value of Response is at
that point.

I also note that the "same" code is in the form's BeforeUpdate event...
while I wouldn't expect this event to occur prior to the label's Click
event, might be a good experiment to put a breakpoint in that code to
see if it runs before your label's Click event does.

--

Ken Snell
<MS ACCESS MVP>

The label name is lblClose
Here goes..

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

'Disable Pg-up and Pg-down keys

Select Case KeyCode
Case 33, 34, 18
KeyCode = 0
Case Else
End Select

End Sub
*************************************
Private Sub Form_Load()

'Turn the MouseWheel Off

Dim blRet As Boolean
blRet = MouseWheelOFF

End Sub
**************************
Private Sub Form_Open(Cancel As Integer)

Me.RecordSource = Forms!frmContacts.RecordSource

Dim rs As DAO.Recordset

If Not IsNull(Me.OpenArgs) Then
Set rs = Me.RecordsetClone
rs.FindFirst "[ContactID]=" & Me.OpenArgs
If rs.NoMatch Then

Else

Me.Bookmark = rs.Bookmark

End If
End If

End Sub
**********************************
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Me.Requery

Else

Me!ContactTypeID.SetFocus

End If
End If

End Sub
*****************************************
Private Sub Form_Close()

Forms!frmContacts.Requery
Forms!frmContacts!lstContacts.Requery
Forms!frmContacts!lstContacts.Selected(0) = True

End Sub

'***************************************
Private Sub lblClose_Click()

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

End Sub
***************************************
Private Sub lblNew_Click()

DoCmd.GoToRecord , , acNewRec
Me!Listing.SetFocus

End Sub

Private Sub PhoneNumber_Click()

Me!PhoneNumber.SelStart = 0

End Sub
***********************************************************************
Private Sub ContactTypeID_NotInList(NewData As String, Response As
Integer)

Dim strSql As String
Dim i As Integer
Dim Msg As String

If Response = acDataErrContinue Then Exit Sub

Msg = "'" & NewData & "' is not currently in the list." & vbCr &
vbCr
Msg = Msg & "Please make a selection that is in the list."

i = MsgBox(Msg, vbInformation + vbOKOnly, "Not In List")

Response = acDataErrContinue

End Sub


The code looks fine. Thus, there must be some other stuff going on in
the code. Post all the code that is in the form's module (if not
1000s of lines long); what is the name of the label control?

--

Ken Snell
<MS ACCESS MVP>

I'm replacing my command buttons with labels for cosmetic reasons.
The following validation code works for the command button but not
for the
label. When I click the label form closes no matter which MsgBox
button I click.
The following code was copied and pasted from the command button to
the label.

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf &
_
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

Any help will be appreciated.
James
 
J

JamesJ

First, I placed a breakpoint in the Form_BeforeUpdate. After clicking
the label the message box came up I clicked Yes and the code halted at the
breakpoint I placed in the form's BeforeUpdate event. Also, on another
form where I haven't replaced the cmd button I placed a breakpoint in the
code of the cmd button's Click event and it halted at that line. Don't know
the code for the label's Click event isn't being triggered after the msgbox.

Ken Snell said:
If the program didn't stop where you expected it to stop, then that
indicates that the code in that part of the program is not being run.
Where did you put the other breakpoint when it stopped? We'll need lots of
detail about this so that we can troubleshoot it with you.

--

Ken Snell
<MS ACCESS MVP>

JamesJ said:
The program doesn't stop at the breakpoint in the procedure?!
I put a breakpoint in another and it halted?

Ken Snell said:
Sorry... hover the cursor over the variable in the code.. a "popup" text
will show the value.

I set a breakpoint at the line but I'm not sure how to view
the value that is returned.

James

Hmmm.... nothing looks suspicious here...

You say you do get the message box to show, but the form closes if you
click Yes button and if you click No button?

Put a breakpoint on the code at the "If Response = vbNo Then" line in
the lblClose_Click event. Let's see what the value of Response is at
that point.

I also note that the "same" code is in the form's BeforeUpdate
event... while I wouldn't expect this event to occur prior to the
label's Click event, might be a good experiment to put a breakpoint in
that code to see if it runs before your label's Click event does.

--

Ken Snell
<MS ACCESS MVP>

The label name is lblClose
Here goes..

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

'Disable Pg-up and Pg-down keys

Select Case KeyCode
Case 33, 34, 18
KeyCode = 0
Case Else
End Select

End Sub
*************************************
Private Sub Form_Load()

'Turn the MouseWheel Off

Dim blRet As Boolean
blRet = MouseWheelOFF

End Sub
**************************
Private Sub Form_Open(Cancel As Integer)

Me.RecordSource = Forms!frmContacts.RecordSource

Dim rs As DAO.Recordset

If Not IsNull(Me.OpenArgs) Then
Set rs = Me.RecordsetClone
rs.FindFirst "[ContactID]=" & Me.OpenArgs
If rs.NoMatch Then

Else

Me.Bookmark = rs.Bookmark

End If
End If

End Sub
**********************************
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Me.Requery

Else

Me!ContactTypeID.SetFocus

End If
End If

End Sub
*****************************************
Private Sub Form_Close()

Forms!frmContacts.Requery
Forms!frmContacts!lstContacts.Requery
Forms!frmContacts!lstContacts.Selected(0) = True

End Sub

'***************************************
Private Sub lblClose_Click()

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

End Sub
***************************************
Private Sub lblNew_Click()

DoCmd.GoToRecord , , acNewRec
Me!Listing.SetFocus

End Sub

Private Sub PhoneNumber_Click()

Me!PhoneNumber.SelStart = 0

End Sub
***********************************************************************
Private Sub ContactTypeID_NotInList(NewData As String, Response As
Integer)

Dim strSql As String
Dim i As Integer
Dim Msg As String

If Response = acDataErrContinue Then Exit Sub

Msg = "'" & NewData & "' is not currently in the list." & vbCr &
vbCr
Msg = Msg & "Please make a selection that is in the list."

i = MsgBox(Msg, vbInformation + vbOKOnly, "Not In List")

Response = acDataErrContinue

End Sub


The code looks fine. Thus, there must be some other stuff going on
in the code. Post all the code that is in the form's module (if not
1000s of lines long); what is the name of the label control?

--

Ken Snell
<MS ACCESS MVP>

I'm replacing my command buttons with labels for cosmetic reasons.
The following validation code works for the command button but not
for the
label. When I click the label form closes no matter which MsgBox
button I click.
The following code was copied and pasted from the command button to
the label.

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf &
_
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

Any help will be appreciated.
James
 
K

Ken Snell [MVP]

What you're seeing is that the form's BeforeUpdate event is the source of
the message box, not the clicking of the label. This suggests to me that the
label is not located in the same "form" or "section" as the data that are
being updated. Are you using a subform for data entry?

If you've put the label in exactly the same place where the command button
had been, and the rest of the form setup is the same, then all should work
as you expect. However, I'm thinking that the setup of your form is not a
"single" form.

Please describe the entire setup of the form -- are you using subforms?
where are the buttons and labels that you're clicking located (on which part
of the form? in which section of the form? in the main form or the
subform?).


--

Ken Snell
<MS ACCESS MVP>



JamesJ said:
First, I placed a breakpoint in the Form_BeforeUpdate. After clicking
the label the message box came up I clicked Yes and the code halted at the
breakpoint I placed in the form's BeforeUpdate event. Also, on another
form where I haven't replaced the cmd button I placed a breakpoint in the
code of the cmd button's Click event and it halted at that line. Don't
know
the code for the label's Click event isn't being triggered after the
msgbox.

Ken Snell said:
If the program didn't stop where you expected it to stop, then that
indicates that the code in that part of the program is not being run.
Where did you put the other breakpoint when it stopped? We'll need lots
of detail about this so that we can troubleshoot it with you.

--

Ken Snell
<MS ACCESS MVP>

JamesJ said:
The program doesn't stop at the breakpoint in the procedure?!
I put a breakpoint in another and it halted?

Sorry... hover the cursor over the variable in the code.. a "popup"
text will show the value.

I set a breakpoint at the line but I'm not sure how to view
the value that is returned.

James

Hmmm.... nothing looks suspicious here...

You say you do get the message box to show, but the form closes if
you click Yes button and if you click No button?

Put a breakpoint on the code at the "If Response = vbNo Then" line in
the lblClose_Click event. Let's see what the value of Response is at
that point.

I also note that the "same" code is in the form's BeforeUpdate
event... while I wouldn't expect this event to occur prior to the
label's Click event, might be a good experiment to put a breakpoint
in that code to see if it runs before your label's Click event does.

--

Ken Snell
<MS ACCESS MVP>

The label name is lblClose
Here goes..

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

'Disable Pg-up and Pg-down keys

Select Case KeyCode
Case 33, 34, 18
KeyCode = 0
Case Else
End Select

End Sub
*************************************
Private Sub Form_Load()

'Turn the MouseWheel Off

Dim blRet As Boolean
blRet = MouseWheelOFF

End Sub
**************************
Private Sub Form_Open(Cancel As Integer)

Me.RecordSource = Forms!frmContacts.RecordSource

Dim rs As DAO.Recordset

If Not IsNull(Me.OpenArgs) Then
Set rs = Me.RecordsetClone
rs.FindFirst "[ContactID]=" & Me.OpenArgs
If rs.NoMatch Then

Else

Me.Bookmark = rs.Bookmark

End If
End If

End Sub
**********************************
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Me.Requery

Else

Me!ContactTypeID.SetFocus

End If
End If

End Sub
*****************************************
Private Sub Form_Close()

Forms!frmContacts.Requery
Forms!frmContacts!lstContacts.Requery
Forms!frmContacts!lstContacts.Selected(0) = True

End Sub

'***************************************
Private Sub lblClose_Click()

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf &
_
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

End Sub
***************************************
Private Sub lblNew_Click()

DoCmd.GoToRecord , , acNewRec
Me!Listing.SetFocus

End Sub

Private Sub PhoneNumber_Click()

Me!PhoneNumber.SelStart = 0

End Sub
***********************************************************************
Private Sub ContactTypeID_NotInList(NewData As String, Response As
Integer)

Dim strSql As String
Dim i As Integer
Dim Msg As String

If Response = acDataErrContinue Then Exit Sub

Msg = "'" & NewData & "' is not currently in the list." & vbCr &
vbCr
Msg = Msg & "Please make a selection that is in the list."

i = MsgBox(Msg, vbInformation + vbOKOnly, "Not In List")

Response = acDataErrContinue

End Sub


message The code looks fine. Thus, there must be some other stuff going on
in the code. Post all the code that is in the form's module (if not
1000s of lines long); what is the name of the label control?

--

Ken Snell
<MS ACCESS MVP>

I'm replacing my command buttons with labels for cosmetic reasons.
The following validation code works for the command button but not
for the
label. When I click the label form closes no matter which MsgBox
button I click.
The following code was copied and pasted from the command button
to the label.

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf
& _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

Any help will be appreciated.
James
 
J

JamesJ

Actually I was trying something a bit different.
The button was in the Header. This is a single form
with no subform. I set the form's border style to
'None' and placed the label captioned with an X in
the detail section of the form, removinmg the form
header and footer.

Ken Snell said:
What you're seeing is that the form's BeforeUpdate event is the source of
the message box, not the clicking of the label. This suggests to me that
the label is not located in the same "form" or "section" as the data that
are being updated. Are you using a subform for data entry?

If you've put the label in exactly the same place where the command button
had been, and the rest of the form setup is the same, then all should work
as you expect. However, I'm thinking that the setup of your form is not a
"single" form.

Please describe the entire setup of the form -- are you using subforms?
where are the buttons and labels that you're clicking located (on which
part of the form? in which section of the form? in the main form or the
subform?).


--

Ken Snell
<MS ACCESS MVP>



JamesJ said:
First, I placed a breakpoint in the Form_BeforeUpdate. After clicking
the label the message box came up I clicked Yes and the code halted at
the
breakpoint I placed in the form's BeforeUpdate event. Also, on another
form where I haven't replaced the cmd button I placed a breakpoint in the
code of the cmd button's Click event and it halted at that line. Don't
know
the code for the label's Click event isn't being triggered after the
msgbox.

Ken Snell said:
If the program didn't stop where you expected it to stop, then that
indicates that the code in that part of the program is not being run.
Where did you put the other breakpoint when it stopped? We'll need lots
of detail about this so that we can troubleshoot it with you.

--

Ken Snell
<MS ACCESS MVP>

The program doesn't stop at the breakpoint in the procedure?!
I put a breakpoint in another and it halted?

Sorry... hover the cursor over the variable in the code.. a "popup"
text will show the value.

I set a breakpoint at the line but I'm not sure how to view
the value that is returned.

James

Hmmm.... nothing looks suspicious here...

You say you do get the message box to show, but the form closes if
you click Yes button and if you click No button?

Put a breakpoint on the code at the "If Response = vbNo Then" line
in the lblClose_Click event. Let's see what the value of Response is
at that point.

I also note that the "same" code is in the form's BeforeUpdate
event... while I wouldn't expect this event to occur prior to the
label's Click event, might be a good experiment to put a breakpoint
in that code to see if it runs before your label's Click event does.

--

Ken Snell
<MS ACCESS MVP>

The label name is lblClose
Here goes..

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

'Disable Pg-up and Pg-down keys

Select Case KeyCode
Case 33, 34, 18
KeyCode = 0
Case Else
End Select

End Sub
*************************************
Private Sub Form_Load()

'Turn the MouseWheel Off

Dim blRet As Boolean
blRet = MouseWheelOFF

End Sub
**************************
Private Sub Form_Open(Cancel As Integer)

Me.RecordSource = Forms!frmContacts.RecordSource

Dim rs As DAO.Recordset

If Not IsNull(Me.OpenArgs) Then
Set rs = Me.RecordsetClone
rs.FindFirst "[ContactID]=" & Me.OpenArgs
If rs.NoMatch Then

Else

Me.Bookmark = rs.Bookmark

End If
End If

End Sub
**********************************
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf &
_
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Me.Requery

Else

Me!ContactTypeID.SetFocus

End If
End If

End Sub
*****************************************
Private Sub Form_Close()

Forms!frmContacts.Requery
Forms!frmContacts!lstContacts.Requery
Forms!frmContacts!lstContacts.Selected(0) = True

End Sub

'***************************************
Private Sub lblClose_Click()

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf &
_
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

End Sub
***************************************
Private Sub lblNew_Click()

DoCmd.GoToRecord , , acNewRec
Me!Listing.SetFocus

End Sub

Private Sub PhoneNumber_Click()

Me!PhoneNumber.SelStart = 0

End Sub
***********************************************************************
Private Sub ContactTypeID_NotInList(NewData As String, Response As
Integer)

Dim strSql As String
Dim i As Integer
Dim Msg As String

If Response = acDataErrContinue Then Exit Sub

Msg = "'" & NewData & "' is not currently in the list." & vbCr &
vbCr
Msg = Msg & "Please make a selection that is in the list."

i = MsgBox(Msg, vbInformation + vbOKOnly, "Not In List")

Response = acDataErrContinue

End Sub


message The code looks fine. Thus, there must be some other stuff going on
in the code. Post all the code that is in the form's module (if
not 1000s of lines long); what is the name of the label control?

--

Ken Snell
<MS ACCESS MVP>

I'm replacing my command buttons with labels for cosmetic
reasons.
The following validation code works for the command button but
not for the
label. When I click the label form closes no matter which MsgBox
button I click.
The following code was copied and pasted from the command button
to the label.

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf
& _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

Any help will be appreciated.
James
 
K

Ken Snell [MVP]

OK so the form setups are now different from what worked before with the
button.

I'm still gathering information for troubleshooting. Describe what actions
you take (editing data, what you click on, etc.) for the sequence that
you're doing.

I'm still not seeing why the label's click event won't run (which is what
you're seeing) and yet the form's beforeupdate event is occurring, which
suggests that somehow the form is losing focus or you're causing the form to
save its data.

Also, leave the breakpoint in the form's beforeupdate event procedure, and
also put a breakpoint on the this line of code in the label's click event:
If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

When you do the label click, does the code run this step? What are the
values of the two controls when it does? Does the form's event run before
the label's click event?

--

Ken Snell
<MS ACCESS MVP>



JamesJ said:
Actually I was trying something a bit different.
The button was in the Header. This is a single form
with no subform. I set the form's border style to
'None' and placed the label captioned with an X in
the detail section of the form, removinmg the form
header and footer.

Ken Snell said:
What you're seeing is that the form's BeforeUpdate event is the source of
the message box, not the clicking of the label. This suggests to me that
the label is not located in the same "form" or "section" as the data that
are being updated. Are you using a subform for data entry?

If you've put the label in exactly the same place where the command
button had been, and the rest of the form setup is the same, then all
should work as you expect. However, I'm thinking that the setup of your
form is not a "single" form.

Please describe the entire setup of the form -- are you using subforms?
where are the buttons and labels that you're clicking located (on which
part of the form? in which section of the form? in the main form or the
subform?).


--

Ken Snell
<MS ACCESS MVP>



JamesJ said:
First, I placed a breakpoint in the Form_BeforeUpdate. After clicking
the label the message box came up I clicked Yes and the code halted at
the
breakpoint I placed in the form's BeforeUpdate event. Also, on another
form where I haven't replaced the cmd button I placed a breakpoint in
the
code of the cmd button's Click event and it halted at that line. Don't
know
the code for the label's Click event isn't being triggered after the
msgbox.

If the program didn't stop where you expected it to stop, then that
indicates that the code in that part of the program is not being run.
Where did you put the other breakpoint when it stopped? We'll need lots
of detail about this so that we can troubleshoot it with you.

--

Ken Snell
<MS ACCESS MVP>

The program doesn't stop at the breakpoint in the procedure?!
I put a breakpoint in another and it halted?

Sorry... hover the cursor over the variable in the code.. a "popup"
text will show the value.

I set a breakpoint at the line but I'm not sure how to view
the value that is returned.

James

message Hmmm.... nothing looks suspicious here...

You say you do get the message box to show, but the form closes if
you click Yes button and if you click No button?

Put a breakpoint on the code at the "If Response = vbNo Then" line
in the lblClose_Click event. Let's see what the value of Response
is at that point.

I also note that the "same" code is in the form's BeforeUpdate
event... while I wouldn't expect this event to occur prior to the
label's Click event, might be a good experiment to put a breakpoint
in that code to see if it runs before your label's Click event
does.

--

Ken Snell
<MS ACCESS MVP>

The label name is lblClose
Here goes..

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

'Disable Pg-up and Pg-down keys

Select Case KeyCode
Case 33, 34, 18
KeyCode = 0
Case Else
End Select

End Sub
*************************************
Private Sub Form_Load()

'Turn the MouseWheel Off

Dim blRet As Boolean
blRet = MouseWheelOFF

End Sub
**************************
Private Sub Form_Open(Cancel As Integer)

Me.RecordSource = Forms!frmContacts.RecordSource

Dim rs As DAO.Recordset

If Not IsNull(Me.OpenArgs) Then
Set rs = Me.RecordsetClone
rs.FindFirst "[ContactID]=" & Me.OpenArgs
If rs.NoMatch Then

Else

Me.Bookmark = rs.Bookmark

End If
End If

End Sub
**********************************
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf &
_
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Me.Requery

Else

Me!ContactTypeID.SetFocus

End If
End If

End Sub
*****************************************
Private Sub Form_Close()

Forms!frmContacts.Requery
Forms!frmContacts!lstContacts.Requery
Forms!frmContacts!lstContacts.Selected(0) = True

End Sub

'***************************************
Private Sub lblClose_Click()

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf
& _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

End Sub
***************************************
Private Sub lblNew_Click()

DoCmd.GoToRecord , , acNewRec
Me!Listing.SetFocus

End Sub

Private Sub PhoneNumber_Click()

Me!PhoneNumber.SelStart = 0

End Sub
***********************************************************************
Private Sub ContactTypeID_NotInList(NewData As String, Response As
Integer)

Dim strSql As String
Dim i As Integer
Dim Msg As String

If Response = acDataErrContinue Then Exit Sub

Msg = "'" & NewData & "' is not currently in the list." & vbCr
& vbCr
Msg = Msg & "Please make a selection that is in the list."

i = MsgBox(Msg, vbInformation + vbOKOnly, "Not In List")

Response = acDataErrContinue

End Sub


message The code looks fine. Thus, there must be some other stuff going
on in the code. Post all the code that is in the form's module
(if not 1000s of lines long); what is the name of the label
control?

--

Ken Snell
<MS ACCESS MVP>

I'm replacing my command buttons with labels for cosmetic
reasons.
The following validation code works for the command button but
not for the
label. When I click the label form closes no matter which MsgBox
button I click.
The following code was copied and pasted from the command button
to the label.

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." &
vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

Any help will be appreciated.
James
 
J

JamesJ

I put a button on the same form with the same code as the OnClick
of the label and the code ran fine from the button.
I test this by clicking a button (cmdNewRec)from an underlying form
and simply entering data in the Listing field and leaving the
ContactTypeID field blank to see if it 'sees' the null in the
ContactTypeID when I click the label.


Ken Snell said:
OK so the form setups are now different from what worked before with the
button.

I'm still gathering information for troubleshooting. Describe what actions
you take (editing data, what you click on, etc.) for the sequence that
you're doing.

I'm still not seeing why the label's click event won't run (which is what
you're seeing) and yet the form's beforeupdate event is occurring, which
suggests that somehow the form is losing focus or you're causing the form
to save its data.

Also, leave the breakpoint in the form's beforeupdate event procedure, and
also put a breakpoint on the this line of code in the label's click event:
If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

When you do the label click, does the code run this step? What are the
values of the two controls when it does? Does the form's event run before
the label's click event?

--

Ken Snell
<MS ACCESS MVP>



JamesJ said:
Actually I was trying something a bit different.
The button was in the Header. This is a single form
with no subform. I set the form's border style to
'None' and placed the label captioned with an X in
the detail section of the form, removinmg the form
header and footer.

Ken Snell said:
What you're seeing is that the form's BeforeUpdate event is the source
of the message box, not the clicking of the label. This suggests to me
that the label is not located in the same "form" or "section" as the
data that are being updated. Are you using a subform for data entry?

If you've put the label in exactly the same place where the command
button had been, and the rest of the form setup is the same, then all
should work as you expect. However, I'm thinking that the setup of your
form is not a "single" form.

Please describe the entire setup of the form -- are you using subforms?
where are the buttons and labels that you're clicking located (on which
part of the form? in which section of the form? in the main form or the
subform?).


--

Ken Snell
<MS ACCESS MVP>



First, I placed a breakpoint in the Form_BeforeUpdate. After clicking
the label the message box came up I clicked Yes and the code halted at
the
breakpoint I placed in the form's BeforeUpdate event. Also, on another
form where I haven't replaced the cmd button I placed a breakpoint in
the
code of the cmd button's Click event and it halted at that line. Don't
know
the code for the label's Click event isn't being triggered after the
msgbox.

If the program didn't stop where you expected it to stop, then that
indicates that the code in that part of the program is not being run.
Where did you put the other breakpoint when it stopped? We'll need
lots of detail about this so that we can troubleshoot it with you.

--

Ken Snell
<MS ACCESS MVP>

The program doesn't stop at the breakpoint in the procedure?!
I put a breakpoint in another and it halted?

Sorry... hover the cursor over the variable in the code.. a "popup"
text will show the value.

I set a breakpoint at the line but I'm not sure how to view
the value that is returned.

James

message Hmmm.... nothing looks suspicious here...

You say you do get the message box to show, but the form closes if
you click Yes button and if you click No button?

Put a breakpoint on the code at the "If Response = vbNo Then" line
in the lblClose_Click event. Let's see what the value of Response
is at that point.

I also note that the "same" code is in the form's BeforeUpdate
event... while I wouldn't expect this event to occur prior to the
label's Click event, might be a good experiment to put a
breakpoint in that code to see if it runs before your label's
Click event does.

--

Ken Snell
<MS ACCESS MVP>

The label name is lblClose
Here goes..

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

'Disable Pg-up and Pg-down keys

Select Case KeyCode
Case 33, 34, 18
KeyCode = 0
Case Else
End Select

End Sub
*************************************
Private Sub Form_Load()

'Turn the MouseWheel Off

Dim blRet As Boolean
blRet = MouseWheelOFF

End Sub
**************************
Private Sub Form_Open(Cancel As Integer)

Me.RecordSource = Forms!frmContacts.RecordSource

Dim rs As DAO.Recordset

If Not IsNull(Me.OpenArgs) Then
Set rs = Me.RecordsetClone
rs.FindFirst "[ContactID]=" & Me.OpenArgs
If rs.NoMatch Then

Else

Me.Bookmark = rs.Bookmark

End If
End If

End Sub
**********************************
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf
& _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Me.Requery

Else

Me!ContactTypeID.SetFocus

End If
End If

End Sub
*****************************************
Private Sub Form_Close()

Forms!frmContacts.Requery
Forms!frmContacts!lstContacts.Requery
Forms!frmContacts!lstContacts.Selected(0) = True

End Sub

'***************************************
Private Sub lblClose_Click()

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf
& _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

End Sub
***************************************
Private Sub lblNew_Click()

DoCmd.GoToRecord , , acNewRec
Me!Listing.SetFocus

End Sub

Private Sub PhoneNumber_Click()

Me!PhoneNumber.SelStart = 0

End Sub
***********************************************************************
Private Sub ContactTypeID_NotInList(NewData As String, Response
As Integer)

Dim strSql As String
Dim i As Integer
Dim Msg As String

If Response = acDataErrContinue Then Exit Sub

Msg = "'" & NewData & "' is not currently in the list." & vbCr
& vbCr
Msg = Msg & "Please make a selection that is in the list."

i = MsgBox(Msg, vbInformation + vbOKOnly, "Not In List")

Response = acDataErrContinue

End Sub


message The code looks fine. Thus, there must be some other stuff going
on in the code. Post all the code that is in the form's module
(if not 1000s of lines long); what is the name of the label
control?

--

Ken Snell
<MS ACCESS MVP>

I'm replacing my command buttons with labels for cosmetic
reasons.
The following validation code works for the command button but
not for the
label. When I click the label form closes no matter which
MsgBox button I click.
The following code was copied and pasted from the command
button to the label.

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." &
vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

Any help will be appreciated.
James
 
K

Ken Snell [MVP]

I am very puzzled by what you're seeing. If you'd like, zip up a copy of the
database (include a form using the command button and a form using the
label) and email it to me. You can get my email address from my munged
"reply to" address -- just remove the words "this is not real" from that
address.

Be sure to include information/instructions that tell me which forms are
which, how to reproduce your situation, etc.

I'll take a look as time permits.
--

Ken Snell
<MS ACCESS MVP>

JamesJ said:
I put a button on the same form with the same code as the OnClick
of the label and the code ran fine from the button.
I test this by clicking a button (cmdNewRec)from an underlying form
and simply entering data in the Listing field and leaving the
ContactTypeID field blank to see if it 'sees' the null in the
ContactTypeID when I click the label.


Ken Snell said:
OK so the form setups are now different from what worked before with the
button.

I'm still gathering information for troubleshooting. Describe what
actions you take (editing data, what you click on, etc.) for the sequence
that you're doing.

I'm still not seeing why the label's click event won't run (which is what
you're seeing) and yet the form's beforeupdate event is occurring, which
suggests that somehow the form is losing focus or you're causing the form
to save its data.

Also, leave the breakpoint in the form's beforeupdate event procedure,
and also put a breakpoint on the this line of code in the label's click
event:
If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

When you do the label click, does the code run this step? What are the
values of the two controls when it does? Does the form's event run before
the label's click event?

--

Ken Snell
<MS ACCESS MVP>



JamesJ said:
Actually I was trying something a bit different.
The button was in the Header. This is a single form
with no subform. I set the form's border style to
'None' and placed the label captioned with an X in
the detail section of the form, removinmg the form
header and footer.

What you're seeing is that the form's BeforeUpdate event is the source
of the message box, not the clicking of the label. This suggests to me
that the label is not located in the same "form" or "section" as the
data that are being updated. Are you using a subform for data entry?

If you've put the label in exactly the same place where the command
button had been, and the rest of the form setup is the same, then all
should work as you expect. However, I'm thinking that the setup of your
form is not a "single" form.

Please describe the entire setup of the form -- are you using subforms?
where are the buttons and labels that you're clicking located (on which
part of the form? in which section of the form? in the main form or the
subform?).


--

Ken Snell
<MS ACCESS MVP>



First, I placed a breakpoint in the Form_BeforeUpdate. After clicking
the label the message box came up I clicked Yes and the code halted at
the
breakpoint I placed in the form's BeforeUpdate event. Also, on another
form where I haven't replaced the cmd button I placed a breakpoint in
the
code of the cmd button's Click event and it halted at that line. Don't
know
the code for the label's Click event isn't being triggered after the
msgbox.

If the program didn't stop where you expected it to stop, then that
indicates that the code in that part of the program is not being run.
Where did you put the other breakpoint when it stopped? We'll need
lots of detail about this so that we can troubleshoot it with you.

--

Ken Snell
<MS ACCESS MVP>

The program doesn't stop at the breakpoint in the procedure?!
I put a breakpoint in another and it halted?

message Sorry... hover the cursor over the variable in the code.. a "popup"
text will show the value.

I set a breakpoint at the line but I'm not sure how to view
the value that is returned.

James

message Hmmm.... nothing looks suspicious here...

You say you do get the message box to show, but the form closes
if you click Yes button and if you click No button?

Put a breakpoint on the code at the "If Response = vbNo Then"
line in the lblClose_Click event. Let's see what the value of
Response is at that point.

I also note that the "same" code is in the form's BeforeUpdate
event... while I wouldn't expect this event to occur prior to the
label's Click event, might be a good experiment to put a
breakpoint in that code to see if it runs before your label's
Click event does.

--

Ken Snell
<MS ACCESS MVP>

The label name is lblClose
Here goes..

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

'Disable Pg-up and Pg-down keys

Select Case KeyCode
Case 33, 34, 18
KeyCode = 0
Case Else
End Select

End Sub
*************************************
Private Sub Form_Load()

'Turn the MouseWheel Off

Dim blRet As Boolean
blRet = MouseWheelOFF

End Sub
**************************
Private Sub Form_Open(Cancel As Integer)

Me.RecordSource = Forms!frmContacts.RecordSource

Dim rs As DAO.Recordset

If Not IsNull(Me.OpenArgs) Then
Set rs = Me.RecordsetClone
rs.FindFirst "[ContactID]=" & Me.OpenArgs
If rs.NoMatch Then

Else

Me.Bookmark = rs.Bookmark

End If
End If

End Sub
**********************************
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." & vbCrLf
& _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Me.Requery

Else

Me!ContactTypeID.SetFocus

End If
End If

End Sub
*****************************************
Private Sub Form_Close()

Forms!frmContacts.Requery
Forms!frmContacts!lstContacts.Requery
Forms!frmContacts!lstContacts.Selected(0) = True

End Sub

'***************************************
Private Sub lblClose_Click()

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." &
vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

End Sub
***************************************
Private Sub lblNew_Click()

DoCmd.GoToRecord , , acNewRec
Me!Listing.SetFocus

End Sub

Private Sub PhoneNumber_Click()

Me!PhoneNumber.SelStart = 0

End Sub
***********************************************************************
Private Sub ContactTypeID_NotInList(NewData As String, Response
As Integer)

Dim strSql As String
Dim i As Integer
Dim Msg As String

If Response = acDataErrContinue Then Exit Sub

Msg = "'" & NewData & "' is not currently in the list." &
vbCr & vbCr
Msg = Msg & "Please make a selection that is in the list."

i = MsgBox(Msg, vbInformation + vbOKOnly, "Not In List")

Response = acDataErrContinue

End Sub


message The code looks fine. Thus, there must be some other stuff going
on in the code. Post all the code that is in the form's module
(if not 1000s of lines long); what is the name of the label
control?

--

Ken Snell
<MS ACCESS MVP>

I'm replacing my command buttons with labels for cosmetic
reasons.
The following validation code works for the command button but
not for the
label. When I click the label form closes no matter which
MsgBox button I click.
The following code was copied and pasted from the command
button to the label.

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." &
vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

Any help will be appreciated.
James
 
J

JamesJ

I zipped it but can't find the email address with "this is not real"
MIne remove _Darwin (my cat's name).

James

Ken Snell said:
I am very puzzled by what you're seeing. If you'd like, zip up a copy of
the database (include a form using the command button and a form using the
label) and email it to me. You can get my email address from my munged
"reply to" address -- just remove the words "this is not real" from that
address.

Be sure to include information/instructions that tell me which forms are
which, how to reproduce your situation, etc.

I'll take a look as time permits.
--

Ken Snell
<MS ACCESS MVP>

JamesJ said:
I put a button on the same form with the same code as the OnClick
of the label and the code ran fine from the button.
I test this by clicking a button (cmdNewRec)from an underlying form
and simply entering data in the Listing field and leaving the
ContactTypeID field blank to see if it 'sees' the null in the
ContactTypeID when I click the label.


Ken Snell said:
OK so the form setups are now different from what worked before with the
button.

I'm still gathering information for troubleshooting. Describe what
actions you take (editing data, what you click on, etc.) for the
sequence that you're doing.

I'm still not seeing why the label's click event won't run (which is
what you're seeing) and yet the form's beforeupdate event is occurring,
which suggests that somehow the form is losing focus or you're causing
the form to save its data.

Also, leave the breakpoint in the form's beforeupdate event procedure,
and also put a breakpoint on the this line of code in the label's click
event:
If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

When you do the label click, does the code run this step? What are the
values of the two controls when it does? Does the form's event run
before the label's click event?

--

Ken Snell
<MS ACCESS MVP>



Actually I was trying something a bit different.
The button was in the Header. This is a single form
with no subform. I set the form's border style to
'None' and placed the label captioned with an X in
the detail section of the form, removinmg the form
header and footer.

What you're seeing is that the form's BeforeUpdate event is the source
of the message box, not the clicking of the label. This suggests to me
that the label is not located in the same "form" or "section" as the
data that are being updated. Are you using a subform for data entry?

If you've put the label in exactly the same place where the command
button had been, and the rest of the form setup is the same, then all
should work as you expect. However, I'm thinking that the setup of
your form is not a "single" form.

Please describe the entire setup of the form -- are you using
subforms? where are the buttons and labels that you're clicking
located (on which part of the form? in which section of the form? in
the main form or the subform?).


--

Ken Snell
<MS ACCESS MVP>



First, I placed a breakpoint in the Form_BeforeUpdate. After clicking
the label the message box came up I clicked Yes and the code halted
at the
breakpoint I placed in the form's BeforeUpdate event. Also, on
another
form where I haven't replaced the cmd button I placed a breakpoint in
the
code of the cmd button's Click event and it halted at that line.
Don't know
the code for the label's Click event isn't being triggered after the
msgbox.

If the program didn't stop where you expected it to stop, then that
indicates that the code in that part of the program is not being
run. Where did you put the other breakpoint when it stopped? We'll
need lots of detail about this so that we can troubleshoot it with
you.

--

Ken Snell
<MS ACCESS MVP>

The program doesn't stop at the breakpoint in the procedure?!
I put a breakpoint in another and it halted?

message Sorry... hover the cursor over the variable in the code.. a
"popup" text will show the value.

I set a breakpoint at the line but I'm not sure how to view
the value that is returned.

James

message Hmmm.... nothing looks suspicious here...

You say you do get the message box to show, but the form closes
if you click Yes button and if you click No button?

Put a breakpoint on the code at the "If Response = vbNo Then"
line in the lblClose_Click event. Let's see what the value of
Response is at that point.

I also note that the "same" code is in the form's BeforeUpdate
event... while I wouldn't expect this event to occur prior to
the label's Click event, might be a good experiment to put a
breakpoint in that code to see if it runs before your label's
Click event does.

--

Ken Snell
<MS ACCESS MVP>

The label name is lblClose
Here goes..

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

'Disable Pg-up and Pg-down keys

Select Case KeyCode
Case 33, 34, 18
KeyCode = 0
Case Else
End Select

End Sub
*************************************
Private Sub Form_Load()

'Turn the MouseWheel Off

Dim blRet As Boolean
blRet = MouseWheelOFF

End Sub
**************************
Private Sub Form_Open(Cancel As Integer)

Me.RecordSource = Forms!frmContacts.RecordSource

Dim rs As DAO.Recordset

If Not IsNull(Me.OpenArgs) Then
Set rs = Me.RecordsetClone
rs.FindFirst "[ContactID]=" & Me.OpenArgs
If rs.NoMatch Then

Else

Me.Bookmark = rs.Bookmark

End If
End If

End Sub
**********************************
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." &
vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Me.Requery

Else

Me!ContactTypeID.SetFocus

End If
End If

End Sub
*****************************************
Private Sub Form_Close()

Forms!frmContacts.Requery
Forms!frmContacts!lstContacts.Requery
Forms!frmContacts!lstContacts.Selected(0) = True

End Sub

'***************************************
Private Sub lblClose_Click()

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." &
vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

End Sub
***************************************
Private Sub lblNew_Click()

DoCmd.GoToRecord , , acNewRec
Me!Listing.SetFocus

End Sub

Private Sub PhoneNumber_Click()

Me!PhoneNumber.SelStart = 0

End Sub
***********************************************************************
Private Sub ContactTypeID_NotInList(NewData As String, Response
As Integer)

Dim strSql As String
Dim i As Integer
Dim Msg As String

If Response = acDataErrContinue Then Exit Sub

Msg = "'" & NewData & "' is not currently in the list." &
vbCr & vbCr
Msg = Msg & "Please make a selection that is in the list."

i = MsgBox(Msg, vbInformation + vbOKOnly, "Not In List")

Response = acDataErrContinue

End Sub


message The code looks fine. Thus, there must be some other stuff
going on in the code. Post all the code that is in the form's
module (if not 1000s of lines long); what is the name of the
label control?

--

Ken Snell
<MS ACCESS MVP>

I'm replacing my command buttons with labels for cosmetic
reasons.
The following validation code works for the command button
but not for the
label. When I click the label form closes no matter which
MsgBox button I click.
The following code was copied and pasted from the command
button to the label.

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." &
vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

Any help will be appreciated.
James
 
D

Douglas J. Steele

Ken's email is (e-mail address removed)

Remove the 13 letters "this is not real" from the address above to use it.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



JamesJ said:
I zipped it but can't find the email address with "this is not real"
MIne remove _Darwin (my cat's name).

James

Ken Snell said:
I am very puzzled by what you're seeing. If you'd like, zip up a copy of
the database (include a form using the command button and a form using the
label) and email it to me. You can get my email address from my munged
"reply to" address -- just remove the words "this is not real" from that
address.

Be sure to include information/instructions that tell me which forms are
which, how to reproduce your situation, etc.

I'll take a look as time permits.
--

Ken Snell
<MS ACCESS MVP>

JamesJ said:
I put a button on the same form with the same code as the OnClick
of the label and the code ran fine from the button.
I test this by clicking a button (cmdNewRec)from an underlying form
and simply entering data in the Listing field and leaving the
ContactTypeID field blank to see if it 'sees' the null in the
ContactTypeID when I click the label.


OK so the form setups are now different from what worked before with
the button.

I'm still gathering information for troubleshooting. Describe what
actions you take (editing data, what you click on, etc.) for the
sequence that you're doing.

I'm still not seeing why the label's click event won't run (which is
what you're seeing) and yet the form's beforeupdate event is occurring,
which suggests that somehow the form is losing focus or you're causing
the form to save its data.

Also, leave the breakpoint in the form's beforeupdate event procedure,
and also put a breakpoint on the this line of code in the label's click
event:
If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

When you do the label click, does the code run this step? What are the
values of the two controls when it does? Does the form's event run
before the label's click event?

--

Ken Snell
<MS ACCESS MVP>



Actually I was trying something a bit different.
The button was in the Header. This is a single form
with no subform. I set the form's border style to
'None' and placed the label captioned with an X in
the detail section of the form, removinmg the form
header and footer.

What you're seeing is that the form's BeforeUpdate event is the
source of the message box, not the clicking of the label. This
suggests to me that the label is not located in the same "form" or
"section" as the data that are being updated. Are you using a subform
for data entry?

If you've put the label in exactly the same place where the command
button had been, and the rest of the form setup is the same, then all
should work as you expect. However, I'm thinking that the setup of
your form is not a "single" form.

Please describe the entire setup of the form -- are you using
subforms? where are the buttons and labels that you're clicking
located (on which part of the form? in which section of the form? in
the main form or the subform?).


--

Ken Snell
<MS ACCESS MVP>



First, I placed a breakpoint in the Form_BeforeUpdate. After
clicking
the label the message box came up I clicked Yes and the code halted
at the
breakpoint I placed in the form's BeforeUpdate event. Also, on
another
form where I haven't replaced the cmd button I placed a breakpoint
in the
code of the cmd button's Click event and it halted at that line.
Don't know
the code for the label's Click event isn't being triggered after the
msgbox.

message If the program didn't stop where you expected it to stop, then that
indicates that the code in that part of the program is not being
run. Where did you put the other breakpoint when it stopped? We'll
need lots of detail about this so that we can troubleshoot it with
you.

--

Ken Snell
<MS ACCESS MVP>

The program doesn't stop at the breakpoint in the procedure?!
I put a breakpoint in another and it halted?

message Sorry... hover the cursor over the variable in the code.. a
"popup" text will show the value.

I set a breakpoint at the line but I'm not sure how to view
the value that is returned.

James

message Hmmm.... nothing looks suspicious here...

You say you do get the message box to show, but the form closes
if you click Yes button and if you click No button?

Put a breakpoint on the code at the "If Response = vbNo Then"
line in the lblClose_Click event. Let's see what the value of
Response is at that point.

I also note that the "same" code is in the form's BeforeUpdate
event... while I wouldn't expect this event to occur prior to
the label's Click event, might be a good experiment to put a
breakpoint in that code to see if it runs before your label's
Click event does.

--

Ken Snell
<MS ACCESS MVP>

The label name is lblClose
Here goes..

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

'Disable Pg-up and Pg-down keys

Select Case KeyCode
Case 33, 34, 18
KeyCode = 0
Case Else
End Select

End Sub
*************************************
Private Sub Form_Load()

'Turn the MouseWheel Off

Dim blRet As Boolean
blRet = MouseWheelOFF

End Sub
**************************
Private Sub Form_Open(Cancel As Integer)

Me.RecordSource = Forms!frmContacts.RecordSource

Dim rs As DAO.Recordset

If Not IsNull(Me.OpenArgs) Then
Set rs = Me.RecordsetClone
rs.FindFirst "[ContactID]=" & Me.OpenArgs
If rs.NoMatch Then

Else

Me.Bookmark = rs.Bookmark

End If
End If

End Sub
**********************************
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." &
vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Me.Requery

Else

Me!ContactTypeID.SetFocus

End If
End If

End Sub
*****************************************
Private Sub Form_Close()

Forms!frmContacts.Requery
Forms!frmContacts!lstContacts.Requery
Forms!frmContacts!lstContacts.Selected(0) = True

End Sub

'***************************************
Private Sub lblClose_Click()

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." &
vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

End Sub
***************************************
Private Sub lblNew_Click()

DoCmd.GoToRecord , , acNewRec
Me!Listing.SetFocus

End Sub

Private Sub PhoneNumber_Click()

Me!PhoneNumber.SelStart = 0

End Sub
***********************************************************************
Private Sub ContactTypeID_NotInList(NewData As String,
Response As Integer)

Dim strSql As String
Dim i As Integer
Dim Msg As String

If Response = acDataErrContinue Then Exit Sub

Msg = "'" & NewData & "' is not currently in the list." &
vbCr & vbCr
Msg = Msg & "Please make a selection that is in the list."

i = MsgBox(Msg, vbInformation + vbOKOnly, "Not In List")

Response = acDataErrContinue

End Sub


message The code looks fine. Thus, there must be some other stuff
going on in the code. Post all the code that is in the form's
module (if not 1000s of lines long); what is the name of the
label control?

--

Ken Snell
<MS ACCESS MVP>

I'm replacing my command buttons with labels for cosmetic
reasons.
The following validation code works for the command button
but not for the
label. When I click the label form closes no matter which
MsgBox button I click.
The following code was copied and pasted from the command
button to the label.

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." &
vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

Any help will be appreciated.
James
 
K

Ken Snell [MVP]

OK - now that I've watched the database in action, I can explain why the
code isn't working when you use a label instead of a command button. The
difference: a command button can receive focus, while a label cannot. What
does this mean?

Well, when you click on a command button, the focus is moved from the
control that is being edited to the command button. This allows the control
to update itself to show the value that you'd entered, and thus the
control's Value property has a non-Null value.

However, when you click on a label, the focus remains in the control that
was being edited. And thus, the control still has a Null value when your
label's Click event procedure occurs. Thus, the code thinks that the textbox
on your form has no value, and thus it runs the "close" process.

If you want to use a label, you'll need to include an extra step in the code
as the first step; namely, move the focus to another control on the form.
So, you could move the focus to the combo box, but note that this will
negate the validation test if the textbox is empty and the combo box is not.
So I suggest that you put a nearly invisible textbox on the form (height and
width of zero), and set the Tab Stop of this textbox to No. Then set the
focus to this textbox in your label's click event before you run the
validation test.
--

Ken Snell
<MS ACCESS MVP>


Ken Snell said:
I am very puzzled by what you're seeing. If you'd like, zip up a copy of
the database (include a form using the command button and a form using the
label) and email it to me. You can get my email address from my munged
"reply to" address -- just remove the words "this is not real" from that
address.

Be sure to include information/instructions that tell me which forms are
which, how to reproduce your situation, etc.

I'll take a look as time permits.
--

Ken Snell
<MS ACCESS MVP>

JamesJ said:
I put a button on the same form with the same code as the OnClick
of the label and the code ran fine from the button.
I test this by clicking a button (cmdNewRec)from an underlying form
and simply entering data in the Listing field and leaving the
ContactTypeID field blank to see if it 'sees' the null in the
ContactTypeID when I click the label.


Ken Snell said:
OK so the form setups are now different from what worked before with the
button.

I'm still gathering information for troubleshooting. Describe what
actions you take (editing data, what you click on, etc.) for the
sequence that you're doing.

I'm still not seeing why the label's click event won't run (which is
what you're seeing) and yet the form's beforeupdate event is occurring,
which suggests that somehow the form is losing focus or you're causing
the form to save its data.

Also, leave the breakpoint in the form's beforeupdate event procedure,
and also put a breakpoint on the this line of code in the label's click
event:
If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

When you do the label click, does the code run this step? What are the
values of the two controls when it does? Does the form's event run
before the label's click event?

--

Ken Snell
<MS ACCESS MVP>



Actually I was trying something a bit different.
The button was in the Header. This is a single form
with no subform. I set the form's border style to
'None' and placed the label captioned with an X in
the detail section of the form, removinmg the form
header and footer.

What you're seeing is that the form's BeforeUpdate event is the source
of the message box, not the clicking of the label. This suggests to me
that the label is not located in the same "form" or "section" as the
data that are being updated. Are you using a subform for data entry?

If you've put the label in exactly the same place where the command
button had been, and the rest of the form setup is the same, then all
should work as you expect. However, I'm thinking that the setup of
your form is not a "single" form.

Please describe the entire setup of the form -- are you using
subforms? where are the buttons and labels that you're clicking
located (on which part of the form? in which section of the form? in
the main form or the subform?).


--

Ken Snell
<MS ACCESS MVP>



First, I placed a breakpoint in the Form_BeforeUpdate. After clicking
the label the message box came up I clicked Yes and the code halted
at the
breakpoint I placed in the form's BeforeUpdate event. Also, on
another
form where I haven't replaced the cmd button I placed a breakpoint in
the
code of the cmd button's Click event and it halted at that line.
Don't know
the code for the label's Click event isn't being triggered after the
msgbox.

If the program didn't stop where you expected it to stop, then that
indicates that the code in that part of the program is not being
run. Where did you put the other breakpoint when it stopped? We'll
need lots of detail about this so that we can troubleshoot it with
you.

--

Ken Snell
<MS ACCESS MVP>

The program doesn't stop at the breakpoint in the procedure?!
I put a breakpoint in another and it halted?

message Sorry... hover the cursor over the variable in the code.. a
"popup" text will show the value.

I set a breakpoint at the line but I'm not sure how to view
the value that is returned.

James

message Hmmm.... nothing looks suspicious here...

You say you do get the message box to show, but the form closes
if you click Yes button and if you click No button?

Put a breakpoint on the code at the "If Response = vbNo Then"
line in the lblClose_Click event. Let's see what the value of
Response is at that point.

I also note that the "same" code is in the form's BeforeUpdate
event... while I wouldn't expect this event to occur prior to
the label's Click event, might be a good experiment to put a
breakpoint in that code to see if it runs before your label's
Click event does.

--

Ken Snell
<MS ACCESS MVP>

The label name is lblClose
Here goes..

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

'Disable Pg-up and Pg-down keys

Select Case KeyCode
Case 33, 34, 18
KeyCode = 0
Case Else
End Select

End Sub
*************************************
Private Sub Form_Load()

'Turn the MouseWheel Off

Dim blRet As Boolean
blRet = MouseWheelOFF

End Sub
**************************
Private Sub Form_Open(Cancel As Integer)

Me.RecordSource = Forms!frmContacts.RecordSource

Dim rs As DAO.Recordset

If Not IsNull(Me.OpenArgs) Then
Set rs = Me.RecordsetClone
rs.FindFirst "[ContactID]=" & Me.OpenArgs
If rs.NoMatch Then

Else

Me.Bookmark = rs.Bookmark

End If
End If

End Sub
**********************************
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." &
vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Me.Requery

Else

Me!ContactTypeID.SetFocus

End If
End If

End Sub
*****************************************
Private Sub Form_Close()

Forms!frmContacts.Requery
Forms!frmContacts!lstContacts.Requery
Forms!frmContacts!lstContacts.Selected(0) = True

End Sub

'***************************************
Private Sub lblClose_Click()

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." &
vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

End Sub
***************************************
Private Sub lblNew_Click()

DoCmd.GoToRecord , , acNewRec
Me!Listing.SetFocus

End Sub

Private Sub PhoneNumber_Click()

Me!PhoneNumber.SelStart = 0

End Sub
***********************************************************************
Private Sub ContactTypeID_NotInList(NewData As String, Response
As Integer)

Dim strSql As String
Dim i As Integer
Dim Msg As String

If Response = acDataErrContinue Then Exit Sub

Msg = "'" & NewData & "' is not currently in the list." &
vbCr & vbCr
Msg = Msg & "Please make a selection that is in the list."

i = MsgBox(Msg, vbInformation + vbOKOnly, "Not In List")

Response = acDataErrContinue

End Sub


message The code looks fine. Thus, there must be some other stuff
going on in the code. Post all the code that is in the form's
module (if not 1000s of lines long); what is the name of the
label control?

--

Ken Snell
<MS ACCESS MVP>

I'm replacing my command buttons with labels for cosmetic
reasons.
The following validation code works for the command button
but not for the
label. When I click the label form closes no matter which
MsgBox button I click.
The following code was copied and pasted from the command
button to the label.

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." &
vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

Any help will be appreciated.
James
 
J

JamesJ

Works fine now!
Thanks for the support.

Thanks again,
James

Ken Snell said:
OK - now that I've watched the database in action, I can explain why the
code isn't working when you use a label instead of a command button. The
difference: a command button can receive focus, while a label cannot.
What does this mean?

Well, when you click on a command button, the focus is moved from the
control that is being edited to the command button. This allows the
control to update itself to show the value that you'd entered, and thus
the control's Value property has a non-Null value.

However, when you click on a label, the focus remains in the control that
was being edited. And thus, the control still has a Null value when your
label's Click event procedure occurs. Thus, the code thinks that the
textbox on your form has no value, and thus it runs the "close" process.

If you want to use a label, you'll need to include an extra step in the
code as the first step; namely, move the focus to another control on the
form. So, you could move the focus to the combo box, but note that this
will negate the validation test if the textbox is empty and the combo box
is not. So I suggest that you put a nearly invisible textbox on the form
(height and width of zero), and set the Tab Stop of this textbox to No.
Then set the focus to this textbox in your label's click event before you
run the validation test.
--

Ken Snell
<MS ACCESS MVP>


Ken Snell said:
I am very puzzled by what you're seeing. If you'd like, zip up a copy of
the database (include a form using the command button and a form using the
label) and email it to me. You can get my email address from my munged
"reply to" address -- just remove the words "this is not real" from that
address.

Be sure to include information/instructions that tell me which forms are
which, how to reproduce your situation, etc.

I'll take a look as time permits.
--

Ken Snell
<MS ACCESS MVP>

JamesJ said:
I put a button on the same form with the same code as the OnClick
of the label and the code ran fine from the button.
I test this by clicking a button (cmdNewRec)from an underlying form
and simply entering data in the Listing field and leaving the
ContactTypeID field blank to see if it 'sees' the null in the
ContactTypeID when I click the label.


OK so the form setups are now different from what worked before with
the button.

I'm still gathering information for troubleshooting. Describe what
actions you take (editing data, what you click on, etc.) for the
sequence that you're doing.

I'm still not seeing why the label's click event won't run (which is
what you're seeing) and yet the form's beforeupdate event is occurring,
which suggests that somehow the form is losing focus or you're causing
the form to save its data.

Also, leave the breakpoint in the form's beforeupdate event procedure,
and also put a breakpoint on the this line of code in the label's click
event:
If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

When you do the label click, does the code run this step? What are the
values of the two controls when it does? Does the form's event run
before the label's click event?

--

Ken Snell
<MS ACCESS MVP>



Actually I was trying something a bit different.
The button was in the Header. This is a single form
with no subform. I set the form's border style to
'None' and placed the label captioned with an X in
the detail section of the form, removinmg the form
header and footer.

What you're seeing is that the form's BeforeUpdate event is the
source of the message box, not the clicking of the label. This
suggests to me that the label is not located in the same "form" or
"section" as the data that are being updated. Are you using a subform
for data entry?

If you've put the label in exactly the same place where the command
button had been, and the rest of the form setup is the same, then all
should work as you expect. However, I'm thinking that the setup of
your form is not a "single" form.

Please describe the entire setup of the form -- are you using
subforms? where are the buttons and labels that you're clicking
located (on which part of the form? in which section of the form? in
the main form or the subform?).


--

Ken Snell
<MS ACCESS MVP>



First, I placed a breakpoint in the Form_BeforeUpdate. After
clicking
the label the message box came up I clicked Yes and the code halted
at the
breakpoint I placed in the form's BeforeUpdate event. Also, on
another
form where I haven't replaced the cmd button I placed a breakpoint
in the
code of the cmd button's Click event and it halted at that line.
Don't know
the code for the label's Click event isn't being triggered after the
msgbox.

message If the program didn't stop where you expected it to stop, then that
indicates that the code in that part of the program is not being
run. Where did you put the other breakpoint when it stopped? We'll
need lots of detail about this so that we can troubleshoot it with
you.

--

Ken Snell
<MS ACCESS MVP>

The program doesn't stop at the breakpoint in the procedure?!
I put a breakpoint in another and it halted?

message Sorry... hover the cursor over the variable in the code.. a
"popup" text will show the value.

I set a breakpoint at the line but I'm not sure how to view
the value that is returned.

James

message Hmmm.... nothing looks suspicious here...

You say you do get the message box to show, but the form closes
if you click Yes button and if you click No button?

Put a breakpoint on the code at the "If Response = vbNo Then"
line in the lblClose_Click event. Let's see what the value of
Response is at that point.

I also note that the "same" code is in the form's BeforeUpdate
event... while I wouldn't expect this event to occur prior to
the label's Click event, might be a good experiment to put a
breakpoint in that code to see if it runs before your label's
Click event does.

--

Ken Snell
<MS ACCESS MVP>

The label name is lblClose
Here goes..

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

'Disable Pg-up and Pg-down keys

Select Case KeyCode
Case 33, 34, 18
KeyCode = 0
Case Else
End Select

End Sub
*************************************
Private Sub Form_Load()

'Turn the MouseWheel Off

Dim blRet As Boolean
blRet = MouseWheelOFF

End Sub
**************************
Private Sub Form_Open(Cancel As Integer)

Me.RecordSource = Forms!frmContacts.RecordSource

Dim rs As DAO.Recordset

If Not IsNull(Me.OpenArgs) Then
Set rs = Me.RecordsetClone
rs.FindFirst "[ContactID]=" & Me.OpenArgs
If rs.NoMatch Then

Else

Me.Bookmark = rs.Bookmark

End If
End If

End Sub
**********************************
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." &
vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Me.Requery

Else

Me!ContactTypeID.SetFocus

End If
End If

End Sub
*****************************************
Private Sub Form_Close()

Forms!frmContacts.Requery
Forms!frmContacts!lstContacts.Requery
Forms!frmContacts!lstContacts.Selected(0) = True

End Sub

'***************************************
Private Sub lblClose_Click()

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." &
vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

End Sub
***************************************
Private Sub lblNew_Click()

DoCmd.GoToRecord , , acNewRec
Me!Listing.SetFocus

End Sub

Private Sub PhoneNumber_Click()

Me!PhoneNumber.SelStart = 0

End Sub
***********************************************************************
Private Sub ContactTypeID_NotInList(NewData As String,
Response As Integer)

Dim strSql As String
Dim i As Integer
Dim Msg As String

If Response = acDataErrContinue Then Exit Sub

Msg = "'" & NewData & "' is not currently in the list." &
vbCr & vbCr
Msg = Msg & "Please make a selection that is in the list."

i = MsgBox(Msg, vbInformation + vbOKOnly, "Not In List")

Response = acDataErrContinue

End Sub


message The code looks fine. Thus, there must be some other stuff
going on in the code. Post all the code that is in the form's
module (if not 1000s of lines long); what is the name of the
label control?

--

Ken Snell
<MS ACCESS MVP>

I'm replacing my command buttons with labels for cosmetic
reasons.
The following validation code works for the command button
but not for the
label. When I click the label form closes no matter which
MsgBox button I click.
The following code was copied and pasted from the command
button to the label.

Dim Response As Integer

If Not IsNull(Me!Listing) And IsNull(Me!ContactTypeID) Then

Response = MsgBox("You failed to enter required data." &
vbCrLf & _
"Do you want to continue editing the record?",
vbExclamation + vbYesNo, _
"Missing Required Data")

If Response = vbNo Then

Me.Undo
Call GlobalClose

Else

Me!ContactTypeID.SetFocus

End If

Else

Call GlobalClose

End If

Any help will be appreciated.
James
 

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