A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Checking for Blanks



 
 
Thread Tools Display Modes
  #1  
Old August 3rd, 2009, 02:58 PM posted to microsoft.public.access.forms
Trini Gal
external usenet poster
 
Posts: 20
Default Checking for Blanks

I have a form with a close button with the following code.

Private Sub btnCCRClose_Click()
On Error GoTo Err_btnCCRClose_Click

Dim ctl As Control

For Each ctl In Me.Detail.Controls
If ctl.Tag = "Required" Then
If Trim(ctl & "") = "" Then
Cancel = True
MsgBox ctl.Name & " is a Required Entry.", vbCritical, "REQUIRED
ENTRY"
ctl.SetFocus
Exit Sub
End If
End If
Next ctl

DoCmd.Close

Exit_btnCCRClose_Click:
Exit Sub

Err_btnCCRClose_Click:
MsgBox Err.Description
Resume Exit_btnCCRClose_Click

End Sub

It worked fine on Friday when I added the code, but now, I’m getting an
error “Object doesn’t support this property or method”.

I originally had the code in the BEFORE UPDATE event of the form. When I
opened it and tried to close it leaving blank, only one “Required Entry”
error would pop up and then it would close anyways, without saving the record.

Can someone please help me or tell me what I’m doing wrong?

Thanks.

  #2  
Old August 3rd, 2009, 05:51 PM posted to microsoft.public.access.forms
Damon Heron[_3_]
external usenet poster
 
Posts: 257
Default Checking for Blanks

the before update event has a (Cancel as Integer) param. The cmd button
does not. Without looking at your code, I would guess part of the problem
is the Cancel= True line. Remark it out and see.

Damon

"Trini Gal" wrote in message
...
I have a form with a close button with the following code.

Private Sub btnCCRClose_Click()
On Error GoTo Err_btnCCRClose_Click

Dim ctl As Control

For Each ctl In Me.Detail.Controls
If ctl.Tag = "Required" Then
If Trim(ctl & "") = "" Then
Cancel = True
MsgBox ctl.Name & " is a Required Entry.", vbCritical,
"REQUIRED
ENTRY"
ctl.SetFocus
Exit Sub
End If
End If
Next ctl

DoCmd.Close

Exit_btnCCRClose_Click:
Exit Sub

Err_btnCCRClose_Click:
MsgBox Err.Description
Resume Exit_btnCCRClose_Click

End Sub

It worked fine on Friday when I added the code, but now, I'm getting an
error "Object doesn't support this property or method".

I originally had the code in the BEFORE UPDATE event of the form. When I
opened it and tried to close it leaving blank, only one "Required Entry"
error would pop up and then it would close anyways, without saving the
record.

Can someone please help me or tell me what I'm doing wrong?

Thanks.



  #3  
Old August 3rd, 2009, 05:56 PM posted to microsoft.public.access.forms
Trini Gal
external usenet poster
 
Posts: 20
Default Checking for Blanks

Never mind, I figured it out. I was SetFocus to a command button.

"Trini Gal" wrote:

I have a form with a close button with the following code.

Private Sub btnCCRClose_Click()
On Error GoTo Err_btnCCRClose_Click

Dim ctl As Control

For Each ctl In Me.Detail.Controls
If ctl.Tag = "Required" Then
If Trim(ctl & "") = "" Then
Cancel = True
MsgBox ctl.Name & " is a Required Entry.", vbCritical, "REQUIRED
ENTRY"
ctl.SetFocus
Exit Sub
End If
End If
Next ctl

DoCmd.Close

Exit_btnCCRClose_Click:
Exit Sub

Err_btnCCRClose_Click:
MsgBox Err.Description
Resume Exit_btnCCRClose_Click

End Sub

It worked fine on Friday when I added the code, but now, I’m getting an
error “Object doesn’t support this property or method”.

I originally had the code in the BEFORE UPDATE event of the form. When I
opened it and tried to close it leaving blank, only one “Required Entry”
error would pop up and then it would close anyways, without saving the record.

Can someone please help me or tell me what I’m doing wrong?

Thanks.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:12 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright 2004-2024 OfficeFrustration.
The comments are property of their posters.