Go Back   Access World Forums > Microsoft Access Discussion > Macros

 
Reply
 
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
Old 09-09-2009, 02:48 PM   #1
Radioactiveduck
Registered User
 
Join Date: Sep 2009
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Radioactiveduck is on a distinguished road
Run-time error '2115'

I have a form with the following fields and data types:

Date: text in "mmm dd, yyyy" format
JAF: checkbox
EFS: checkbox
txt_ChAttn: textbox, generic format
Note: textbox, generic format

Basically, I've written code that does an AfterUpdate whenever JAF or EFS are checked or unchecked. It writes "John Doe" or "Jane Doe" into the txt_ChAttn textbox depending on which one is checked. I get the following vba error whenever it runs, however:

Run-time error '2115':

the macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing Microsoft Office Access from saving the data in the field.

Now, I checked the results, and it actually is updating the txt_ChAttn textbox correctly, but it still throws this error every time you check or uncheck the checkboxes. Here is the code for the updates:


Private Sub EFS_AfterUpdate()

If EFS = -1 Then
If JAF = -1 Then
Me.txt_ChAttn.SetFocus
Me.txt_ChAttn.Text = "John Doe, Jane Doe"
Me.Refresh
Else
Me.txt_ChAttn.SetFocus
Me.txt_ChAttn.Text = "John Doe"
Me.Refresh
End If
Else
If JAF = -1 Then
Me.txt_ChAttn.SetFocus
Me.txt_ChAttn.Text = "Jane Doe"
Me.Refresh
Else
Me.txt_ChAttn.SetFocus
Me.txt_ChAttn.Text = ""
Me.Refresh
End If
End If

End Sub

Private Sub JAF_AfterUpdate()

If EFS = -1 Then
If JAF = -1 Then
Me.txt_ChAttn.SetFocus
Me.txt_ChAttn.Text = "John Doe, Jane Doe"
Me.Refresh
Else
Me.txt_ChAttn.SetFocus
Me.txt_ChAttn.Text = "John Doe"
Me.Refresh
End If
Else
If JAF = -1 Then
Me.txt_ChAttn.SetFocus
Me.txt_ChAttn.Text = "Jane Doe"
Me.Refresh
Else
Me.txt_ChAttn.SetFocus
Me.txt_ChAttn.Text = ""
Me.Refresh
End If
End If

End Sub


Depending on which conditions are met, it always highlights the
"Me.txt_ChAttn.Text =" line, regardless of which combination of checked/unchecked the textboxes fall under. Any ideas on what's causing this error, and how I can get rid of it? As I said, it is updating the textbox correctly.

EDIT: I can't seem to force it to post the code with the correct text spacing, so it may look a bit sloppy.


Last edited by Radioactiveduck; 09-09-2009 at 02:57 PM.
Radioactiveduck is offline   Reply With Quote
Old 09-09-2009, 02:55 PM   #2
boblarson
Smeghead
 
boblarson's Avatar
 
Join Date: Jan 2001
Location: Oregon, USA
Posts: 32,068
Thanks: 97
Thanked 1,806 Times in 1,573 Posts
boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold boblarson is a splendid one to behold
Re: Run-time error '2115'

1. Get rid of the .Text part on all of it. You don't use the .Text syntax in VBA unless you absolutely have to. The default of controls is the .Value property and so you can just use

Me.txt_ChAttn = "Jane Doe"

as an example.


2. You do not need the Me.Refresh after everything.

So,
Code:
Private Sub EFS_AfterUpdate()

If EFS = -1 Then
   If JAF = -1 Then
      Me.txt_ChAttn = "John Doe, Jane Doe"
   Else
      Me.txt_ChAttn = "John Doe"
   End If
Else
   IF JAF = -1 Then
        Me.txt_ChAttn = "Jane Doe"
   Else
       Me.txt_ChAttn = ""
   End If
End If
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
boblarson is offline   Reply With Quote
Old 09-13-2009, 06:00 PM   #3
Radioactiveduck
Registered User
 
Join Date: Sep 2009
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Radioactiveduck is on a distinguished road
Re: Run-time error '2115'

Sweet, thanks! That fixed it.

Radioactiveduck is offline   Reply With Quote
Old 09-13-2009, 11:02 PM   #4
Atomic Shrimp
Humanoid lifeform
 
Join Date: Jun 2000
Location: Portsmouth, England
Posts: 1,954
Thanks: 0
Thanked 8 Times in 7 Posts
Atomic Shrimp has a spectacular aura about Atomic Shrimp has a spectacular aura about
Re: Run-time error '2115'

Nice username

Maybe it's just me, but I think the repetition in those condition tests indicates they shouldn't be nested. I'd do it like this:

Code:
If EFS = -1 Then Me.txt_ChAttn = "John Doe"
If JAF = -1 Then
  If Me.txt_ChAttn <>"" then Me.txt_ChAttn = Me.txt_ChAttn & ", "
  Me.txt_ChAttn = Me.txt_ChAttn & "Jane Doe"
End If
As far as I can tell, the above will yield the same result in all cases.

__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
- it's not radioactive, and contains only a few crustaceans.
Atomic Shrimp is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Working with Date and time fields wjburke2 Forms 10 01-04-2011 07:11 AM
Run time error '13' Type mismatch alant37 Modules & VBA 1 06-22-2005 06:32 AM
Run Time Error - No Value Given RichardH Modules & VBA 3 06-16-2005 04:17 AM
Run Time Error 2001 - What am I doing wrong? zeee Reports 0 01-06-2005 07:52 AM
Run Time Error after refreshing the form zeee Forms 0 01-06-2005 07:12 AM




All times are GMT -8. The time now is 05:52 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World