Public Sub code problem

Jon123

Registered User.
Local time
Today, 07:09
Joined
Aug 29, 2003
Messages
668
I have this code in the after update property of a field on a tabform. I cant seem to get it to work at all and I thinking that this may be due to the fact that the form is a tabform and may not support. Anyone with any ideas please help

jon

Code:
Public Sub update_AfterUpdate()
     Me.temp1 = Null
     Me.temp2 = Null
     Me.[amatdelays] = 0
     Me.[IBMdelays] = 0
Dim x As Integer
Dim y As Integer

   x = IIf(Me.[qual] <= 4, 1, 2)  ' or <=4, depending on what you decide
   y = IIf(Me.[GtoGminusqual] <= 63, 5, 7)  ' or <=61, depending on what you decide

   Select Case (x + y)
      Case 6
         Me.[GtoGNoDelays] = [GtoGrounded]
      Case 8
         Me.[temp1] = Me.[GtoGminusqual] - 63
         Me.[amatdelays] = Me.[amatdelays] + [temp1]
         Me.[GtoGNoDelays] = Me.[GtoGrounded] - [amatdelays]
      Case 7
         Me.[GtoGNoDelays] = Me.[GtoGminusqual] + 4
         Me.[temp2] = Me.[qual] - 4
         Me.[IBMdelays] = Me.[IBMdelays] + [temp2]
      Case 9
         Me.[GtoGNoDelays] = 67
         Me.[temp1] = Me.[GtoGminusqual] - 63
         Me.[amatdelays] = Me.[amatdelays] + [temp1]
         Me.[temp2] = Me.[qual] - 4
         Me.[IBMdelays] = Me.[IBMdelays] + [temp2]
   End Select
End sub
 
Can you please indicate exactly what is not working. The code seems to be working as you have it designed. Some of the fields/controls you refer to are not explained in your posting, but the best I could test, the code is working. The values being assigned to X and Y are being assigned correctly and the various Case options are being accessed based on the value returned by adding X and Y together.
 
Yes sorry. I have this code on the afterupdat property of a text box. When I update this field Access closes no error just a message box to report it to microsoft box . I had it working on a regular form I started having problems when moving it to a tabform.

jon
 
Have you tried placing a break point in the code to see if you can tell which line it is failing on?
 
Yes if I put a stop right after the Public Sub it will stop there if I put a stop afer the 1st line Me.temp1 = Null then it crashes access ?

I just cant get a handle on this one
 
This is really strange behavior. Is is possible for you to post your database with most of the data removed, but enough for us to tests?
 
agree I can try to strip it down to upload.
 
If these:
Me.temp1
Me.temp2

are text boxes, don't try setting to null, but instead an empty string ""

Me.temp1 = ""
Me.temp2 = ""

especially if they are unbound.
 
I have this code in the after update property of a field on a tabform. I cant seem to get it to work at all and I thinking that this may be due to the fact that the form is a tabform and may not support. Anyone with any ideas please help

jon

Code:
Public Sub update_AfterUpdate()
     Me.temp1 = Null
     Me.temp2 = Null
     Me.[amatdelays] = 0
     Me.[IBMdelays] = 0
Dim x As Integer
Dim y As Integer

   x = IIf(Me.[qual] <= 4, 1, 2)  ' or <=4, depending on what you decide
   y = IIf(Me.[GtoGminusqual] <= 63, 5, 7)  ' or <=61, depending on what you decide

   Select Case (x + y)
      Case 6
         Me.[GtoGNoDelays] = [GtoGrounded]
      Case 8
         Me.[temp1] = Me.[GtoGminusqual] - 63
         Me.[amatdelays] = Me.[amatdelays] + [temp1]
         Me.[GtoGNoDelays] = Me.[GtoGrounded] - [amatdelays]
      Case 7
         Me.[GtoGNoDelays] = Me.[GtoGminusqual] + 4
         Me.[temp2] = Me.[qual] - 4
         Me.[IBMdelays] = Me.[IBMdelays] + [temp2]
      Case 9
         Me.[GtoGNoDelays] = 67
         Me.[temp1] = Me.[GtoGminusqual] - 63
         Me.[amatdelays] = Me.[amatdelays] + [temp1]
         Me.[temp2] = Me.[qual] - 4
         Me.[IBMdelays] = Me.[IBMdelays] + [temp2]
   End Select
End sub
Sorry - read it as the form AfterUpdate. At form AfterUpdate the recordsource is not available.
 
Last edited:
SOS, I tried that same problem. Wis, I dont understand?

jon
 
there is an afterupdate for the form, which deals with the result of saving the reocrd

there is an after update for the control which deals with just that control -

i think that is what was meant
 
it depends what you are doing

when you enter data into a control (eg a textbox, or a combo box) and immediately after you need to do something, then add the code to the CONTROL's before or after update event

if you have somewthing you need to do before/after you save the whole record, then you need the FORM's event.
 
Ok I understand. I'm just using the control after update to trigger the code. Its not using the value entered in that text box for any part of the code its just the trigger.

jon
 
oK now I'm even more confused. I tried to down size the program in order to post
and when doing so the code now works so I must have something labeled wrong somewhere.
 
So I got it working but dont know why or why it was shutting down access . I replaced all of the Me. with well see code
Code:
Public Sub Update_Click()
    [Forms]![Frm-DPN wetcleanpage]![temp1] = Null
    [Forms]![Frm-DPN wetcleanpage]![temp2] = Null
    [Forms]![Frm-DPN wetcleanpage]![amatdelays] = 0
    [Forms]![Frm-DPN wetcleanpage]![IBMdelays] = 0
Dim x As Integer
Dim y As Integer

   x = IIf([Forms]![Frm-DPN wetcleanpage]![qual] <= 4, 1, 2)  ' or <=4, depending on what you decide
   y = IIf([Forms]![Frm-DPN wetcleanpage]![GtoGminusqual] <= 63, 5, 7)  ' or <=61, depending on what you decide

I left out the whole code but you get the idea

Now for some reason it works fine

jon
 
Jon,

If this code is running from within the same form, then replacing the Me with the long reference to the form would not have made a difference.

I am curious as to just what did make it work.
 
Mr. B I would not lie I have been working on this for 2 days long days and I spent the better part of this morning trying to pull out just enough of the dbase to send up so you could see it. But once I got it out it worked at posted. So that didnt work. I then just for kicks I did not think it would work either so I replaced all of the 'Me.' in the code with the long reference to the form / fields and it worked thats all I did.

Jon
 
Well, if it is working..... That's great, but I am one that just likes to know what was wrong and what I did to fix it.

Oh, well, if it ain't broke, don't fix it.
 
NO I agree with you I just dont know what to do next. I was going to put all of the Me. back in by changing them 1 at a time and see where it trips up. I just dont have time right now it will have to wait until tonight by I would like to know too.

will post any findings

jon
 

Users who are viewing this thread

Back
Top Bottom