Counter Problem

  • Thread starter Marcelino Benitez via AccessMonster.com
  • Start date
M

Marcelino Benitez via AccessMonster.com

I running a work order application. I have a counter field that contains a
letter, julian date and a counter number. Ok I have an A, B, C, D, E, F, G, X,
R company. Ok when I start my date and select B I have a counter beggining on
number 1. Then if I select A first of the day in this company will give me 02
instead of 01. Why I don't know need some help. This is the code that I use.

Private Sub Company_AfterUpdate()
Dim count As Variant
Dim compdate As Variant
Dim JDate As Integer
Dim Ydate As Integer '
Dim t As Variant 'Counter variable

Me.Undo
Form.Requery
DoCmd.GoToRecord , , acLast 'Send the page to the last record
compdate = Text31
'MsgBox Text31

DoCmd.GoToRecord , , acNewRec

JDate = Format(Date, "y")
Ydate = Format(Date, "yy")

If JDate < 10 Then
tdate = Company & Ydate & "0" & "0" & JDate & "-" & "01"
End If

If JDate >= 10 Then
tdate = Company & Ydate & "0" & JDate & "-" & "01"
End If

If JDate > 99 Then
tdate = Company & Ydate & JDate & "-" & "01"
End If

'MsgBox [tdate]

If compdate > tdate Or compdate = tdate Then
t = Format(compdate, "!&&")
If t < 99 Then
t = t + 1
t = Format(t, "00")
End If

If JDate < 10 Then
WONum = Company & Ydate & "0" & "0" & JDate & "-" & t
End If

If JDate >= 10 Then
WONum = Company & Ydate & "0" & JDate & "-" & t
End If

If JDate > 99 Then
WONum = Company & Ydate & JDate & "-" & t
End If
Else
WONum = tdate

End If

DoCmd.GoToControl "Model"

End Sub
 
R

Rob Oldfield

Your best plan is going to be to step through your code to see where it's
going wrong. To do that...

Go to the code window and right click the DoCmd.GoToRecord , , acLast line.
Choose Toggle, Breakpoint. That line will be highlighted.
Now close the code window and switch to form view. Update the company and
it should run through the code and stop when it reaches the breakpoint you
just set.
Hit F8. It will move to the next line to process.
Hit F8 again... etc, etc.
You can hit F5 and code will continue normally at any time (but will halt
again the next time it reaches a breakpoint), you can also wave the mouse at
any variable to see what it is currently set as.

Hopefully, you should be able to use this to see where the code is taking a
different path from what you expect, and to identify which variable is
causing it to take that wrong path.
 
M

Marcelino Benitez via AccessMonster.com

Hey Rob can I send you my application and that way you can check please. My
email is (e-mail address removed). Thanks in advance.

Marcelino
Rob said:
Your best plan is going to be to step through your code to see where it's
going wrong. To do that...

Go to the code window and right click the DoCmd.GoToRecord , , acLast line.
Choose Toggle, Breakpoint. That line will be highlighted.
Now close the code window and switch to form view. Update the company and
it should run through the code and stop when it reaches the breakpoint you
just set.
Hit F8. It will move to the next line to process.
Hit F8 again... etc, etc.
You can hit F5 and code will continue normally at any time (but will halt
again the next time it reaches a breakpoint), you can also wave the mouse at
any variable to see what it is currently set as.

Hopefully, you should be able to use this to see where the code is taking a
different path from what you expect, and to identify which variable is
causing it to take that wrong path.
I running a work order application. I have a counter field that contains a
letter, julian date and a counter number. Ok I have an A, B, C, D, E, F, G, X,
[quoted text clipped - 60 lines]
 
R

Rob Oldfield

That's not a road I want to go down I'm afraid. What does the debug thing
give you?


Marcelino Benitez via AccessMonster.com said:
Hey Rob can I send you my application and that way you can check please. My
email is (e-mail address removed). Thanks in advance.

Marcelino
Rob said:
Your best plan is going to be to step through your code to see where it's
going wrong. To do that...

Go to the code window and right click the DoCmd.GoToRecord , , acLast line.
Choose Toggle, Breakpoint. That line will be highlighted.
Now close the code window and switch to form view. Update the company and
it should run through the code and stop when it reaches the breakpoint you
just set.
Hit F8. It will move to the next line to process.
Hit F8 again... etc, etc.
You can hit F5 and code will continue normally at any time (but will halt
again the next time it reaches a breakpoint), you can also wave the mouse at
any variable to see what it is currently set as.

Hopefully, you should be able to use this to see where the code is taking a
different path from what you expect, and to identify which variable is
causing it to take that wrong path.
I running a work order application. I have a counter field that contains a
letter, julian date and a counter number. Ok I have an A, B, C, D, E,
F, G, X,
[quoted text clipped - 60 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top