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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|