Error with Code in Form OnCurrent

KristenD

Registered User.
Local time
Today, 14:32
Joined
Apr 2, 2012
Messages
394
I had help with a code in order to help with the entry of a form by "graying out" certain boxes unless a criteria was met. When I put the code in it errors out and says "the expression OnCurrent you entered as the event property setting prduced the following error: Return without GoSub,
  • The expression may not result in the name of a macro, the name of a user defined function or [Event Procedure].
  • The error may have been an error evaluating the function, event or macro.
Here is the code I used:
Code:
Option Compare Database
Private Sub Form_Current()
    If Me.frmOSHATraining.EmploymentStatus = "Eligible" Or "No Rehire" Then
        Me.frmOSHATraining.JobNumber.Enabled = False
        Me.frmOSHATraining.JobNumber.Locked = True
        Me.frmOSHATraining.JobSite.Enabled = False
        Me.frmOSHATraining.JobSite.Locked = True
        Me.frmOSHATraining.CraftCode.Enabled = False
        Me.frmOSHATraining.CraftCode.Locked = True
    Else
        Me.frmOSHATraining.JobNumber.Enabled = True
        Me.frmOSHATraining.JobNumber.Locked = False
        Me.frmOSHATraining.JobSite.Enabled = True
        Me.frmOSHATraining.JobSite.Locked = False
        Me.frmOSHATraining.CraftCode.Enabled = True
        Me.frmOSHATraining.CraftCode.Locked = False
    End If
End Sub
Private Sub Form_AfterUpdate()
      If Me.frmOSHATraining.EmploymentStatus = "Eligible" Or "No Rehire" Then
        Me.frmOSHATraining.JobNumber.Enabled = False
        Me.frmOSHATraining.JobNumber.Locked = True
        Me.frmOSHATraining.JobSite.Enabled = False
        Me.frmOSHATraining.JobSite.Locked = True
        Me.frmOSHATraining.CraftCode.Enabled = False
        Me.frmOSHATraining.CraftCode.Locked = True
    Else
        Me.frmOSHATraining.JobNumber.Enabled = True
        Me.frmOSHATraining.JobNumber.Locked = False
        Me.frmOSHATraining.JobSite.Enabled = True
        Me.frmOSHATraining.JobSite.Locked = False
        Me.frmOSHATraining.CraftCode.Enabled = True
        Me.frmOSHATraining.CraftCode.Locked = False
    End If
End Sub

Then it also says Compile error: Method or data member not found. :banghead:

I followed the code exactly as it was given to me in a previous thread.
 
What line of code does it highlight when you click the Debug button on the error message box?

By the way, do you know what the WITH block is?
 
It turns red sometimes depending on what I change or it highlights it yellow with an arrow.

I don't know what the WITH block is. I am learning this all on my own with the help of this forum and Google!

Thank you!!
 
So what line of code does it highlight yellow when it errors?

I will show you an example of the WITH block later. Let's fix this first.
 
It highlights the Private Sub line on both forms. I do have this code on two forms as that was the advice given to me. So I have it on the main form EmployeeEntry as well as the subform frmOSHATraining on both the OnCurrent and After_Update lines.
 
If you mean on the Visual Basic tab, then yes. Otherwise I'm not sure what module that would be.
 
Look at your list of objects... i.e. Forms, Tables, Queries, Modules, Macros.
 
No there is no Module for that code. I just have my export module there.
 
I don't understand. Upload a stripped down version of your db let's have a look.
 
I guess I should ask again, what form should I be looking at? ;)
 
I'm sorry it is EmployeeEntry and then the tab form that I am having an issue with is frmOSHATraining.
 
OK, I've changed your code a bit and got it to work for what you want it to do (I believe).

It could be tidied up a touch and I think rather than using an AfterUpdate event on the form you might be better placing it in the AfterUpdate event of the combo box where you choose the values such as "eligible" etc.

Hope this helps a bit :)
 

Attachments

I'm hoping Addyman's changes works for you. I haven't had the time to look at your db yet.
 
It is still giving me an error with the Job Number telling me it needs information in there.
 
Also it keeps giving me a compile error again...not sure why.
 
I copied and pasted the code from the database that was reposted but now I am getting 3 errors. I checked, double checked and triple checked to make sure I have the code where it needs to be and it is where it supposed to be.

The 3 errors I keep getting are:
  1. The expression On Current you entered as the event property setting prduced the following error: Ambiguous name detected: Form_Current.
  2. The Link Master fields property setting has prduced this error 'Ambiguous name detected: Form_Current.
  3. The Mocrosoft Office Access database engine cannot find a record in thetblJobs with key, matching field(s) 'JobNumber'.
:banghead: Is there an easier way to get what I want done that I am missing??

Thanks for all your help!! :)
 
Right, I have removed (not fixed) all the errors when the form loads and now you need to start from scratch by explaining what you're trying to do.

It's apparent that you're not conversant with coding in VBA because of how you've made calls to functions and areas where you've placed code. I would advise that rather than adding things you're not sure of, simply ask where it should go. Makes life easier.

Use the attached as your template.
 

Attachments

What I would like to see happen is on the OSHA tab is:
  • If in the Main Form (EmployeeEntry) the Employment Status is either Eligible or No Rehire or Disability then I want the following fields "grayed out" in the OSHA tab: EmployeeType, CraftCode, JobNumber and JobSite.
  • If in the the Main Form, the Employment Status is Active, then I want those fields "active"
  • Also, and I don't understand why it won't happen in this subform, but I want the Employee ID field to automatically populate in the subform for OSHA like it does in the Skills Inventory tab.
That is what I'm looking to accomplish!

Thank you!!
 

Users who are viewing this thread

Back
Top Bottom