WUGNET, the Windows User Group Network
Your Complete Resource Center for "The Best" in Shareware, Computing Tips and Support, Windows Industry News... and much more!
Home Forums Shareware Windows Tips Hot Offers FREE Newsletters Arcade Contact Us About Partners
Search WUGNET: RSS Feeds RSS Feeds Advertise with WUGNET    |    Shareware eBooks
HomeHome FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

After Update_Event Pocedure

 
   Home -> Office other -> Getting Started RSS
Next:  Data Type problem  
Author Message
Roger Bell

External


Since: Mar 02, 2006
Posts: 185



(Msg. 1) Posted: Tue Sep 02, 2008 12:52 am
Post subject: After Update_Event Pocedure
Archived from groups: microsoft>public>access>gettingstarted (more info?)

I have a field in a Data Form called "Section Name" and this is a Text Field
where the user enters for example 1A, 1B etc.

I would like an After Update event Procedure which prevents the user from
entering duplicates with an appropriate error message. I have been able to
do this with a number field but not with a text field.

This is the code I used for a number field:
Private Sub Envelope_Number_AfterUpdate()
If IsNull(Me.Envelope_Number) = True Then
'Do nothing NUll is acceptable
DoCmd.RunCommand acCmdSaveRecord
[Combo561].Requery

ElseIf DCount("*", "[Main Table]", "[Envelope Number]=" &
Me.Envelope_Number) > 0 Then
MsgBox "SORRY, THIS NUMBER IS ALREADY IN USE. IF YOU WISH TO ALLOCATE THIS
NUMBER, YOU MUST REMOVE THE NUMBER FROM THE MEMBER TO WHOM IT IS CURRENTLY
ALLOCATED. PLEASE NOTE THAT YOU MUST NOT RE-ALLOCATE ENVELOPE NUMBERS DURING
THE PLANNED GIVING CYCLE AS THIS WILL AFFECT THE FINANCIAL REPORTING",
vbOKOnly, "ERROR! MESSAGE"
Cancel = True
Me.[Envelope Number] = Null
DoCmd.RunCommand acCmdSaveRecord
End If
End Sub

Can the above code be modified for a text field?

Thanks for any help
Back to top
Login to vote
Dennis

External


Since: Oct 19, 2004
Posts: 762



(Msg. 2) Posted: Tue Sep 02, 2008 1:06 am
Post subject: RE: After Update_Event Pocedure [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

For text fields you need to surround your field with single quotes

DCount("*", "[Main Table]", "[Text Field]= '" & Me.Text_Field & "'") > 0

"Roger Bell" wrote:

> I have a field in a Data Form called "Section Name" and this is a Text Field
> where the user enters for example 1A, 1B etc.
>
> I would like an After Update event Procedure which prevents the user from
> entering duplicates with an appropriate error message. I have been able to
> do this with a number field but not with a text field.
>
> This is the code I used for a number field:
> Private Sub Envelope_Number_AfterUpdate()
> If IsNull(Me.Envelope_Number) = True Then
> 'Do nothing NUll is acceptable
> DoCmd.RunCommand acCmdSaveRecord
> [Combo561].Requery
>
> ElseIf DCount("*", "[Main Table]", "[Envelope Number]=" &
> Me.Envelope_Number) > 0 Then
> MsgBox "SORRY, THIS NUMBER IS ALREADY IN USE. IF YOU WISH TO ALLOCATE THIS
> NUMBER, YOU MUST REMOVE THE NUMBER FROM THE MEMBER TO WHOM IT IS CURRENTLY
> ALLOCATED. PLEASE NOTE THAT YOU MUST NOT RE-ALLOCATE ENVELOPE NUMBERS DURING
> THE PLANNED GIVING CYCLE AS THIS WILL AFFECT THE FINANCIAL REPORTING",
> vbOKOnly, "ERROR! MESSAGE"
> Cancel = True
> Me.[Envelope Number] = Null
> DoCmd.RunCommand acCmdSaveRecord
> End If
> End Sub
>
> Can the above code be modified for a text field?
>
> Thanks for any help
>
>
Back to top
Login to vote
Klatuu

External


Since: Apr 06, 2005
Posts: 2923



(Msg. 3) Posted: Tue Sep 02, 2008 8:29 am
Post subject: RE: After Update_Event Pocedure [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Just to clarify, Dennins, Jet SQL will accept either single or double quotes;
however, there can be a danger using single quotes. That is in the case
where the data may contain a single quote. This most common situation is
name fields where you may run into an O'Reilly, for example.

I know that trying to get the right number of quotes when using double
quotes is daunting. I had a really hard time of it myself. I tried some
functions I downloaded and some constants, but nothing seemed to work in all
cases and frankly, obsfucated the code. So I came up with my own way of
doing it. First, the rule is that when you want to put a double quote in a
string, you use two double quotes ""
But then, you still have to use quotes to delimit the string and that is
where I would almost always get it wrong. When I got it right, it was purely
accidental. So here is what I did. I would first write the statement using
single quotes:

DCount("*", "[Main Table]", "[Text Field]= '" & Me.Text_Field & "'") > 0

Now since what I really want is a double quote everywhere there is a single
quote, I would just go back and replace all the single quotes with two double
quotes.

DCount("*", "[Main Table]", "[Text Field]= """ & Me.Text_Field & """") > 0

After a while, you don't even have to go through the first step. It becomes
natural where the quotes go.

And a note to the OP. When you only want to test for the existance of a
value in a field, the DLookup is usually much faster. The DCount has to
examine each value in the field, create an internal varialbe, and add 1 to it
each time it finds a match. The DLookup only looks for the value and stops
when it finds the first match. I would suggest, instead:

If Not IsNull(DLookup("[TextField]", "[Main Table]", "[Text Field]= """
& Me.Text_Field & """")) Then
'The Value was Found
Else
'The Value is not in the field
End If


--
Dave Hargis, Microsoft Access MVP


"Dennis" wrote:

> For text fields you need to surround your field with single quotes
>
> DCount("*", "[Main Table]", "[Text Field]= '" & Me.Text_Field & "'") > 0
>
> "Roger Bell" wrote:
>
> > I have a field in a Data Form called "Section Name" and this is a Text Field
> > where the user enters for example 1A, 1B etc.
> >
> > I would like an After Update event Procedure which prevents the user from
> > entering duplicates with an appropriate error message. I have been able to
> > do this with a number field but not with a text field.
> >
> > This is the code I used for a number field:
> > Private Sub Envelope_Number_AfterUpdate()
> > If IsNull(Me.Envelope_Number) = True Then
> > 'Do nothing NUll is acceptable
> > DoCmd.RunCommand acCmdSaveRecord
> > [Combo561].Requery
> >
> > ElseIf DCount("*", "[Main Table]", "[Envelope Number]=" &
> > Me.Envelope_Number) > 0 Then
> > MsgBox "SORRY, THIS NUMBER IS ALREADY IN USE. IF YOU WISH TO ALLOCATE THIS
> > NUMBER, YOU MUST REMOVE THE NUMBER FROM THE MEMBER TO WHOM IT IS CURRENTLY
> > ALLOCATED. PLEASE NOTE THAT YOU MUST NOT RE-ALLOCATE ENVELOPE NUMBERS DURING
> > THE PLANNED GIVING CYCLE AS THIS WILL AFFECT THE FINANCIAL REPORTING",
> > vbOKOnly, "ERROR! MESSAGE"
> > Cancel = True
> > Me.[Envelope Number] = Null
> > DoCmd.RunCommand acCmdSaveRecord
> > End If
> > End Sub
> >
> > Can the above code be modified for a text field?
> >
> > Thanks for any help
> >
> >
Back to top
Login to vote
Display posts from previous:   
       Home -> Office other -> Getting Started All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Categories:
 Windows XP
 Windows Vista
 Windows Other
 Office
  Office Other
 Security
 WinRAR
  • Home |
  • Shareware |
  • Windows Tips |
  • Hot Offers |
  • FREE Newsletters |
  • Arcade |
  • Forums |
  • eBooks |
  • About WUGNET |
  • Partners |
  • Contact

  • WUGNET Privacy Policy |
  • Link to WUGNET