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  

How do you save a field?



 
 
Thread Tools Display Modes
  #1  
Old October 4th, 2006, 03:49 PM posted to microsoft.public.access.forms
Claudette Hennessy
external usenet poster
 
Posts: 43
Default How do you save a field?

I have a form with txtFirstName and txtLastName. The client has asked to be
notified if the input folk enter a first and last name which is already in
the database.

The procedure below is working as is, however after the entry in txtLastName
is undone, I would like to move to the txtFirstName control and undo that
also.
I have tried DoCmd.GoToControl "txtFirstName" and then Me!txtFirstNameUndo,
but get runtime error message 2018, " I must save the field. " How?
DoCmd.Save does not list an acfield.

Private Sub txtLastName_BeforeUpdate(Cancel As Integer)

If (Not IsNull(DLookup("[LastName]", "tblStaff", "[LastName] ='" _
& Me!txtLastName & "'" & " AND [FirstName] ='" & Me!txtFirstName &
"'"))) Then
MsgBox "This person has already been entered in the database."
Cancel = True
Me!txtLastName.Undo

End If
End Sub

Any help appreciated..






  #2  
Old October 4th, 2006, 04:16 PM posted to microsoft.public.access.forms
Jeff L
external usenet poster
 
Posts: 448
Default How do you save a field?

If all you are trying to do is blank out the first name, then
Me.txtFirstName = "" will do it.

Hope that helps!


Claudette Hennessy wrote:
I have a form with txtFirstName and txtLastName. The client has asked to be
notified if the input folk enter a first and last name which is already in
the database.

The procedure below is working as is, however after the entry in txtLastName
is undone, I would like to move to the txtFirstName control and undo that
also.
I have tried DoCmd.GoToControl "txtFirstName" and then Me!txtFirstNameUndo,
but get runtime error message 2018, " I must save the field. " How?
DoCmd.Save does not list an acfield.

Private Sub txtLastName_BeforeUpdate(Cancel As Integer)

If (Not IsNull(DLookup("[LastName]", "tblStaff", "[LastName] ='" _
& Me!txtLastName & "'" & " AND [FirstName] ='" & Me!txtFirstName &
"'"))) Then
MsgBox "This person has already been entered in the database."
Cancel = True
Me!txtLastName.Undo

End If
End Sub

Any help appreciated..


  #3  
Old October 4th, 2006, 04:25 PM posted to microsoft.public.access.forms
ruralguy via AccessMonster.com
external usenet poster
 
Posts: 1,172
Default How do you save a field?

Hi Claudette,
Have you just tried:

Me!txtLastName.Undo
Me!txtFirstName.Undo

The control does not need the focus to use this method.

If that does not work then try:

Me!txtLastName.Undo
Me!txtFirstName = Me!txtFirstName.OldValue

Claudette Hennessy wrote:
I have a form with txtFirstName and txtLastName. The client has asked to be
notified if the input folk enter a first and last name which is already in
the database.

The procedure below is working as is, however after the entry in txtLastName
is undone, I would like to move to the txtFirstName control and undo that
also.
I have tried DoCmd.GoToControl "txtFirstName" and then Me!txtFirstNameUndo,
but get runtime error message 2018, " I must save the field. " How?
DoCmd.Save does not list an acfield.

Private Sub txtLastName_BeforeUpdate(Cancel As Integer)

If (Not IsNull(DLookup("[LastName]", "tblStaff", "[LastName] ='" _
& Me!txtLastName & "'" & " AND [FirstName] ='" & Me!txtFirstName &
"'"))) Then
MsgBox "This person has already been entered in the database."
Cancel = True
Me!txtLastName.Undo

End If
End Sub

Any help appreciated..


--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via http://www.accessmonster.com

  #4  
Old October 4th, 2006, 05:15 PM posted to microsoft.public.access.forms
Claudette Hennessy
external usenet poster
 
Posts: 43
Default How do you save a field?

The focus in on txtLastName at the start of the procedure.

Me!txtLastName.Undo
Me!txtFirstName.Undo

blanks out txtLastName, and has no effect on txtFirstName.

Me!txtLastName.Undo
Me!txtFirstName = Me!txtFirstName.OldValue

generates error 438, object does not support this property or method.

Me!txtLastName = " ' generates error 2115, 'the function set to beforeupdate
is preventing Event Tracking from saving the field" ????

In any case, after txtLastName and txtFirstName are returned to " ", I want
to GoToControl txtFirstName so correct data can be input.

I thought this was going to be so simple.

"ruralguy via AccessMonster.com" u12102@uwe wrote in message
news:6744388f37db0@uwe...
Hi Claudette,
Have you just tried:

Me!txtLastName.Undo
Me!txtFirstName.Undo



The control does not need the focus to use this method.

If that does not work then try:

Me!txtLastName.Undo
Me!txtFirstName = Me!txtFirstName.OldValue

Claudette Hennessy wrote:
I have a form with txtFirstName and txtLastName. The client has asked to
be
notified if the input folk enter a first and last name which is already in
the database.

The procedure below is working as is, however after the entry in
txtLastName
is undone, I would like to move to the txtFirstName control and undo that
also.
I have tried DoCmd.GoToControl "txtFirstName" and then
Me!txtFirstNameUndo,
but get runtime error message 2018, " I must save the field. " How?
DoCmd.Save does not list an acfield.

Private Sub txtLastName_BeforeUpdate(Cancel As Integer)

If (Not IsNull(DLookup("[LastName]", "tblStaff", "[LastName] ='" _
& Me!txtLastName & "'" & " AND [FirstName] ='" & Me!txtFirstName &
"'"))) Then
MsgBox "This person has already been entered in the database."
Cancel = True
Me!txtLastName.Undo

End If
End Sub

Any help appreciated..


--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via http://www.accessmonster.com



  #5  
Old October 4th, 2006, 05:39 PM posted to microsoft.public.access.forms
ruralguy via AccessMonster.com
external usenet poster
 
Posts: 1,172
Default How do you save a field?

I take it these are UNBOUND TextBoxes. You might try Me.UnDo in the
*AfterUpdate* event of the txtLastName control rather than the BeforeUpdate
event and then use a Me!txtFirstName.SetFocus to move back to the other
control.

Claudette Hennessy wrote:
The focus in on txtLastName at the start of the procedure.

Me!txtLastName.Undo
Me!txtFirstName.Undo

blanks out txtLastName, and has no effect on txtFirstName.

Me!txtLastName.Undo
Me!txtFirstName = Me!txtFirstName.OldValue

generates error 438, object does not support this property or method.

Me!txtLastName = " ' generates error 2115, 'the function set to beforeupdate
is preventing Event Tracking from saving the field" ????

In any case, after txtLastName and txtFirstName are returned to " ", I want
to GoToControl txtFirstName so correct data can be input.

I thought this was going to be so simple.

Hi Claudette,
Have you just tried:

Me!txtLastName.Undo
Me!txtFirstName.Undo


The control does not need the focus to use this method.

[quoted text clipped - 30 lines]

Any help appreciated..


--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via http://www.accessmonster.com

  #6  
Old October 4th, 2006, 06:28 PM posted to microsoft.public.access.forms
Claudette Hennessy
external usenet poster
 
Posts: 43
Default How do you save a field?

It worked ! Thank you. Here is the complete procedu


Private Sub txtLastName_AfterUpdate()
If (Not IsNull(DLookup("[LastName]", "tblStaff", "[LastName] ='" _
& Me!txtLastName & "'" & " AND [FirstName] ='" & Me!txtFirstName &
"'"))) Then
MsgBox "This person has already been entered in the database."
Cancel = True
Me!txtLastName = " "
Me!txtFirstName.SetFocus
Me!txtFirstName = " "

End If
End Sub

Again, many thanks.
Claudette
"ruralguy via AccessMonster.com" u12102@uwe wrote in message
news:6744decb450f1@uwe...
I take it these are UNBOUND TextBoxes. You might try Me.UnDo in the
*AfterUpdate* event of the txtLastName control rather than the
BeforeUpdate
event and then use a Me!txtFirstName.SetFocus to move back to the other
control.

Claudette Hennessy wrote:
The focus in on txtLastName at the start of the procedure.

Me!txtLastName.Undo
Me!txtFirstName.Undo

blanks out txtLastName, and has no effect on txtFirstName.

Me!txtLastName.Undo
Me!txtFirstName = Me!txtFirstName.OldValue

generates error 438, object does not support this property or method.

Me!txtLastName = " ' generates error 2115, 'the function set to
beforeupdate
is preventing Event Tracking from saving the field" ????

In any case, after txtLastName and txtFirstName are returned to " ", I
want
to GoToControl txtFirstName so correct data can be input.

I thought this was going to be so simple.

Hi Claudette,
Have you just tried:

Me!txtLastName.Undo
Me!txtFirstName.Undo


The control does not need the focus to use this method.

[quoted text clipped - 30 lines]

Any help appreciated..


--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via http://www.accessmonster.com



  #7  
Old October 4th, 2006, 07:57 PM posted to microsoft.public.access.forms
ruralguy via AccessMonster.com
external usenet poster
 
Posts: 1,172
Default How do you save a field?

That is great Claudette! By the way, you do *not* need Cancel = True in the
AfterUpdate event. I would also recommend initializing your TextBoxes to
ZeroLengthStrings (ZLS) rather than a single space. In other words Me!
txtLastName = "" rather than Me!txtlastName = " ".

Claudette Hennessy wrote:
It worked ! Thank you. Here is the complete procedu

Private Sub txtLastName_AfterUpdate()
If (Not IsNull(DLookup("[LastName]", "tblStaff", "[LastName] ='" _
& Me!txtLastName & "'" & " AND [FirstName] ='" & Me!txtFirstName &
"'"))) Then
MsgBox "This person has already been entered in the database."
Cancel = True
Me!txtLastName = " "
Me!txtFirstName.SetFocus
Me!txtFirstName = " "

End If
End Sub

Again, many thanks.
Claudette
I take it these are UNBOUND TextBoxes. You might try Me.UnDo in the
*AfterUpdate* event of the txtLastName control rather than the

[quoted text clipped - 35 lines]

Any help appreciated..


--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via http://www.accessmonster.com

  #8  
Old October 4th, 2006, 08:14 PM posted to microsoft.public.access.forms
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default How do you save a field?

If that code actually works for Claudette, it implies to me that she's not
using Option Explicit, since Cancel hasn't been declared in that routine.

Claudette: make sure that your class module has Option Explicit as its first
line (or it can be the 2nd line, after the Option Compare Database line). To
have this automatically happen, select Tools | Options while in the VB
Editor, and go to the Module tab. Make sure the checkbox "Require Variable
Declaration" is checked.

The reason for this is that forcing you to declare all variables will
prevent the kind of errors that occur if you've got code like:

intLoop = 1
Do While intLoop 10
' do something here
intLoo = intLoop + 1
Loop

You'd have an infinite loop there, since intLoop's value never gets
incremented because of the typo.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"ruralguy via AccessMonster.com" u12102@uwe wrote in message
news:67461321f7d6a@uwe...
That is great Claudette! By the way, you do *not* need Cancel = True in
the
AfterUpdate event. I would also recommend initializing your TextBoxes to
ZeroLengthStrings (ZLS) rather than a single space. In other words Me!
txtLastName = "" rather than Me!txtlastName = " ".

Claudette Hennessy wrote:
It worked ! Thank you. Here is the complete procedu

Private Sub txtLastName_AfterUpdate()
If (Not IsNull(DLookup("[LastName]", "tblStaff", "[LastName] ='" _
& Me!txtLastName & "'" & " AND [FirstName] ='" & Me!txtFirstName &
"'"))) Then
MsgBox "This person has already been entered in the database."
Cancel = True
Me!txtLastName = " "
Me!txtFirstName.SetFocus
Me!txtFirstName = " "

End If
End Sub

Again, many thanks.
Claudette
I take it these are UNBOUND TextBoxes. You might try Me.UnDo in the
*AfterUpdate* event of the txtLastName control rather than the

[quoted text clipped - 35 lines]

Any help appreciated..


--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via http://www.accessmonster.com



  #9  
Old October 4th, 2006, 08:54 PM posted to microsoft.public.access.forms
ruralguy via AccessMonster.com
external usenet poster
 
Posts: 1,172
Default How do you save a field?

I couldn't agree more Doug. Claudette, when you add the Option Explicit to
your Form module it will cause an error if you use a variable in a subroutine
and haven't declared it yet. Just go through and add Dim statements to the
SubRoutines that need them and thise errors will go away and you will be fine.


Douglas J. Steele wrote:
If that code actually works for Claudette, it implies to me that she's not
using Option Explicit, since Cancel hasn't been declared in that routine.

Claudette: make sure that your class module has Option Explicit as its first
line (or it can be the 2nd line, after the Option Compare Database line). To
have this automatically happen, select Tools | Options while in the VB
Editor, and go to the Module tab. Make sure the checkbox "Require Variable
Declaration" is checked.

The reason for this is that forcing you to declare all variables will
prevent the kind of errors that occur if you've got code like:

intLoop = 1
Do While intLoop 10
' do something here
intLoo = intLoop + 1
Loop

You'd have an infinite loop there, since intLoop's value never gets
incremented because of the typo.

That is great Claudette! By the way, you do *not* need Cancel = True in
the

[quoted text clipped - 24 lines]

Any help appreciated..


--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via http://www.accessmonster.com

 




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 07:17 PM.


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