Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

run-error 2108 2

Status
Not open for further replies.

mac5

Programmer
May 31, 2002
5
US
I am using this code to force an entry in CHKNUM if PDCHK is entered. Everything is fine till I ok that a check number must be entered. Then I receive the run-time error "You must save the field before you execute the GoToControl Action.

I'm probably missing the obvious but am stuck.

Thanks,
Bill


Private Sub CHKNUM_BeforeUpdate(Cancel As Integer)

If Not IsNull(PDCHK) Then
If IsNull(CHKNUM) Then
MsgBox "You must enter a check number", vbInformation
DoCmd.CancelEvent
DoCmd.GoToControl "CHKNUM"
Exit Sub
End If
End If
End Sub
 
I'm not sure about you, but before I tell it to go to CHKNUM, you might want to make sure you're not IN CHKNUM in the first place - what you're saying here is 'go to myself if the conditions aren't met'

Usually, you would, depending on your Tab Control settings, check if the CHKNUM is filled prior to leaving a form or a pertinent tab and this is normally not IN the CHKNUM. Plus, you're doing the check BeforeUpdate of the actual field.

Reevaluate where you want to check to see if CHKNUM is populated and put the coding there. Also, instead of nested If's, try:

If Not IsNull(PDCHK) and IsNull(CHKNUM) Then
...
End If

This way, the coding only has to check once instead of checking twice. More efficient if you're concerned with Stacks and whatnot.
Roy
aka BanditWk
Las Vegas, NV
roy@cccamerica.org
RLMBandit@aol.com (private)
 
You are already in the CHKNUM field when you are in the before update event of CHKNUM. All you have to do is cancel the event. The focus should remain in CHKNUM so there is no reason to go there.

Rather than do a docmd.cancelevent why not just say cancel = 1. If for some reason you want to change the focus, try
me.controlname.setfocus.

Robert Berman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top