473,395 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to create an identifier to indicate a break in sequence?

18
I am trying to modify a Access 2003 Sales report that pulls serial numbers assigned to sales orders. The modification needed is to add an identifier (anything, color, etc...) to show when there is a break in the serial number sequence.

example: Sales order # 46783
SN's assigned and shipped
4670110
4680110
**4700110
4710110
4720110
4730110
**4780110
4790110

** Identifies a break in the serial number sequence for this Sales order.

My dilemma is how to create this identifier on the report. The report is tied to an SQL statement in VBA.

I have limited knowledge of Access and VBA, so any help is greatly appreciated.
Jan 27 '11 #1
19 2129
TheSmileyCoder
2,322 Expert Mod 2GB
Dear Swen

I have uploaded a simple example of using the reports Detail_Format event to show or hide a line depending on whether or not the serial number is sequential. If you have any questions regarding the code, feel free to ask. I have also posted the code here.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3. Private lngLast As Long
  4.  
  5.  
  6. Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  7.     'Format the appearance of the skipper line
  8.     If lngLast = 0 Then
  9.         'Special case, this is the first detail, before lngLast gets assigned a value.
  10.         'Just assign value and exit
  11.         lngLast = Me.tb_Serial
  12.         Me.LineSkipper.Visible = False
  13.         Exit Sub
  14.     End If
  15.  
  16.  
  17.     'Record the last value used in detail format. This is important as a detail can be formatted multiple times
  18.     If lngLast = Me.tb_Serial Then
  19.         'We are looking at the same detail as last time code ran, so just exit
  20.         Exit Sub
  21.     Else
  22.         'We are looking at a new detail, lets compare it to the old one
  23.         If Me.tb_Serial > lngLast + 10000 Then
  24.             Me.LineSkipper.Visible = True
  25.             lngLast = Me.tb_Serial
  26.             Else
  27.             Me.LineSkipper.Visible = False
  28.             lngLast = Me.tb_Serial
  29.         End If
  30.     End If
  31. End Sub
Attached Files
File Type: zip Skipper.zip (22.5 KB, 86 views)
Jan 27 '11 #2
swen
18
TheSmileyOne

Thank you for the attachement and code. I changed the code to apply to the fields within my report and was not able to get it to work.

Here is the code that my report is generated from:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2.  
  3. If IsNull(Form_frm_RunRPT.BegSerial) And IsNull(Form_frm_RunRPT.EndSerial) And IsNull(Form_frm_RunRPT.SNso) = True Then
  4.     MsgBox "The Serial Number range and Sales Order Number fields are blank." & vbCrLf & "Therefor, this report contains ALL Serial Numbers for this part."
  5. End If
  6.  
  7.  
  8. Dim lngLen As Long
  9. Dim strSQL_FROM As String
  10. Dim strSQL_WHERE As String
  11. Dim strSQL As String
  12.  
  13.  
  14. strSQL_FROM = "FROM TestCase "
  15.  
  16. strSQL_WHERE = "WHERE ((TestCase.TopAssyNo)=[Forms]![frm_RunRPT]![TopNo]) AND "
  17.  
  18.     If [Forms]![frm_RunRPT]![BegSerial] >= 0 Then
  19.         strSQL_WHERE = strSQL_WHERE & "((TestCase.SerialNo) Between [Forms]![frm_RunRPT]![BegSerial] And [Forms]![frm_RunRPT]![EndSerial]) AND "
  20.     End If
  21.     If [Forms]![frm_RunRPT]![SNso] >= 0 Then
  22.         strSQL_WHERE = strSQL_WHERE & "((TestCase.SONo) = [Forms]![frm_RunRPT]![SNso]) AND "
  23.     End If
  24.  
  25.     'Use these values to process a final search string
  26.     'There will be an extra " AND " at the end of the string, so we must compensate
  27.     lngLen = Len(strSQL_WHERE) - 5      ' " AND " is 5 chars long
  28.  
  29.     If lngLen <= 6 Then     'Now we check the length to decide if we need to process
  30.         'The where clause is NULL - Default to base recordsource
  31.         Me.RecordSource = "Qry_SerialCkout2"
  32.  
  33.     Else
  34.         'The where clause contained search info - we will process the string
  35.         strSQL_WHERE = left$(strSQL_WHERE, lngLen)  'Trim off the last " AND " (5 chars)
  36.  
  37.         strSQL = strSQL_FROM & strSQL_WHERE     'Join the FROM and the final WHERE clauses
  38.  
  39.         Me.RecordSource = ("SELECT TestCase.SerialNoID, TestCase.TopAssyNo, TestCase.SerialNo, TestCase.Date, " & _
  40.         "TestCase.CustPO, TestCase.DesignNotes, TestCase.PlateColor, TestCase.Line, TestCase.SONo, " & _
  41.         "TestCase.CustName, TestCase.FullSN " & strSQL & " ORDER BY TestCase.SerialNo")
  42.  
  43.     End If
  44.  
  45.  
  46.  
  47. End Sub
The user inputs their required info on the "RunRpt" form and generates the report via the command btn. The data is pulled form the "TestCase" table that contains over 170,000 records via the above VBA code.

If the user is needing a range of serial numbers, the report is queried via the "SerialNo" field but the report shows the "FullSN" field. (FullSN = (SerialNo + Date(format mm/yy)). The "FullSN" field type is "number" on the table, so I'm not sure why your code did not work.

I am new to Access and VBA, but learn quickly when things are explained to me. Again, any help is greatly appreciated.
Jan 27 '11 #3
swen
18
I got the "Line skipper" to work. I had to add the "SerialNo" field to the report, change the code to look at that field, and calculate "+1".

Now I get a debug message "you entered an expression that has no value" on "lngLast = Me.SerialNo". This happens when the user does not enter any search criteria which invokes the msgbox code on the report open.

Do I need to change the location of the "Line skipper" code or am I missing something simple?
Jan 31 '11 #4
TheSmileyCoder
2,322 Expert Mod 2GB
Can you post your code and tell me which line the code stops on? Sorry, I seem to have missed your first reply, thats why I have not returned earlier.
Jan 31 '11 #5
swen
18
When the report opens and the user did not input a criteria on the "RunRPT" form, the msgbox code on line "3" appears.(This is correct). After the user selects the "OK" to this msgbox, the debug error appears "you entered an expression that has no value" and focuses on line "54" of the below code. (The below code is the only code on this report).

Thank you for your assistance with this.


Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2. If IsNull(Form_frm_RunRPT.BegSerial) And IsNull(Form_frm_RunRPT.EndSerial) And IsNull(Form_frm_RunRPT.SNso) = True Then
  3.     MsgBox "The Serial Number range and Sales Order Number fields are blank." & vbCrLf & "Therefor, this report contains ALL Serial Numbers for this part."
  4.     Exit Sub
  5. End If
  6.  
  7.  
  8. Dim lngLen As Long
  9. Dim strSQL_FROM As String
  10. Dim strSQL_WHERE As String
  11. Dim strSQL As String
  12.  
  13.  
  14. strSQL_FROM = "FROM TestCase "
  15.  
  16. strSQL_WHERE = "WHERE ((TestCase.TopAssyNo)=[Forms]![frm_RunRPT]![TopNo]) AND "
  17.  
  18.     If [Forms]![frm_RunRPT]![BegSerial] >= 0 Then
  19.         strSQL_WHERE = strSQL_WHERE & "((TestCase.SerialNo) Between [Forms]![frm_RunRPT]![BegSerial] And [Forms]![frm_RunRPT]![EndSerial]) AND "
  20.     End If
  21.     If [Forms]![frm_RunRPT]![SNso] >= 0 Then
  22.         strSQL_WHERE = strSQL_WHERE & "((TestCase.SONo) = [Forms]![frm_RunRPT]![SNso]) AND "
  23.     End If
  24.  
  25.     'Use these values to process a final search string
  26.     'There will be an extra " AND " at the end of the string, so we must compensate
  27.     lngLen = Len(strSQL_WHERE) - 5      ' " AND " is 5 chars long
  28.  
  29.     If lngLen <= 6 Then     'Now we check the length to decide if we need to process
  30.         'The where clause is NULL - Default to base recordsource
  31.         Me.RecordSource = "Qry_SerialCkout2"
  32.  
  33.     Else
  34.         'The where clause contained search info - we will process the string
  35.         strSQL_WHERE = left$(strSQL_WHERE, lngLen)  'Trim off the last " AND " (5 chars)
  36.  
  37.         strSQL = strSQL_FROM & strSQL_WHERE     'Join the FROM and the final WHERE clauses
  38.  
  39.         Me.RecordSource = ("SELECT TestCase.SerialNoID, TestCase.TopAssyNo, TestCase.SerialNo, TestCase.Date, " & _
  40.         "TestCase.CustPO, TestCase.DesignNotes, TestCase.PlateColor, TestCase.Line1, TestCase.SONo, " & _
  41.         "TestCase.CustName, TestCase.FullSN " & strSQL & " ORDER BY TestCase.SerialNo")
  42.  
  43.  
  44.     End If
  45.  
  46.  
  47. End Sub
  48.  
  49. Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  50.     'Format the appearance of the skipper line
  51.     If lngLast = 0 Then
  52.         'Special case, this is the first detail, before lngLast gets assigned a value.
  53.         'Just assign value and exit
  54.         lngLast = Me.SerialNo
  55.         Me.LineSkipper.Visible = False
  56.         Exit Sub
  57.     End If
  58.  
  59.  
  60.     'Record the last value used in detail format. This is important as a detail can be formatted multiple times
  61.     If lngLast = Me.SerialNo Then
  62.         'We are looking at the same detail as last time code ran, so just exit
  63.         Exit Sub
  64.     Else
  65.         'We are looking at a new detail, lets compare it to the old one
  66.         If Me.SerialNo > lngLast + 1 Then
  67.             Me.LineSkipper.Visible = True
  68.             lngLast = Me.SerialNo
  69.             Else
  70.             Me.LineSkipper.Visible = False
  71.             lngLast = Me.SerialNo
  72.         End If
  73.     End If
  74.  
  75. End Sub
  76.  
Jan 31 '11 #6
TheSmileyCoder
2,322 Expert Mod 2GB
Okay, I see now what is happening.

Id be willing to bet that in your table, you have a record, where the Serial Nr has not been filled in. It is essentially Null which is not the same as 0. Your only seing this when your user does not enter a input range, because when he does enter a input range, the null records gets filtered away.

First find the record (you can usually find it by opening the table, and filtering for Null, and decide whether or not its meant to be there, or if its an error.

If its not meant to be there, delete it, and make sure your system prevents you from entering records without a serial number. (You can set the field to Required)

If its meant to be there, we need to handle the cases where we might meet a Null.

The way to handle this is to add an expression to catch the Nulls and turn them into something harmless. An example could be Nz (built in access function). It has 2 arguments, the argument we want to check (SerialNo) and the argument we want to use if SerialNo is null.
Example use:
Expand|Select|Wrap|Line Numbers
  1. lngLast=Nz(Me.SerialNo,-10)
Now if SerialNo is null, the null will be replaced by a harmless -10. The reason I choose -10 is because its not something that will occur naturally in your values, and because I've allready assigned another meaning to the case lngLast=0.

Now everywhere you use Me.SerialNo you should replace it with Nz(Me.SerialNo,-10)
Jan 31 '11 #7
swen
18
Quick question... would I replace Line 54 with "lngLast=Nz(Me.SerialNo,-10)"? Or insert it somewhere?
Jan 31 '11 #8
swen
18
Total newbe... disregard the previous question. I replaced every instance of "Me.SerialNo" but still get the same debug error message on the same line of code.

I verified that the SerialNo field on the base table is "Required" and that there are not any records with a Null value.

Any ideas?
Jan 31 '11 #9
TheSmileyCoder
2,322 Expert Mod 2GB
Hmm....
Whats the SQL of Qry_SerialCkout2?
Jan 31 '11 #10
swen
18
The default query "Qry_SerialCkout2" (code below) only pulls data via a Serial range. Where as the code on the report includes the "SNso" (sales order) criteria.

Qry_SerialCkout2 code:
Expand|Select|Wrap|Line Numbers
  1. SELECT TestCase.SerialNoID, TestCase.TopAssyNo, TestCase.SerialNo, TestCase.Date, (IIf(IsNull([Line1]),[SONo],[SONo] & "-" & [Line1])) AS [Sales Order], TestCase.CustName, TestCase.CustPO, TestCase.DesignNotes, TestCase.PlateColor, TestCase.SONo, TestCase.Line1, TestCase.FullSN
  2. FROM TestCase
  3. WHERE (((TestCase.TopAssyNo)=[Forms]![frm_RunRPT]![TopNo]) AND ((TestCase.SerialNo) Between [Forms]![frm_RunRPT]![BegSerial] And [Forms]![frm_RunRPT]![EndSerial]) AND (([Forms]![frm_RunRPT]![BegSerial]) Is Not Null) AND (([Forms]![frm_RunRPT]![endSerial]) Is Not Null)) OR (((TestCase.TopAssyNo)=[Forms]![frm_RunRPT]![TopNo]) AND ((TestCase.SerialNo) Is Null) AND (([Forms]![frm_RunRPT]![BegSerial]) Is Null) AND (([Forms]![frm_RunRPT]![endSerial]) Is Null))
  4. ORDER BY TestCase.SerialNo, TestCase.Date, TestCase.SerialNo;
  5.  
Jan 31 '11 #11
TheSmileyCoder
2,322 Expert Mod 2GB
Well I don't really have anything good to offer at this time.

Your welcome to upload the database here, or mail it to me, if you want it private. It can be hard to offer debugging assistance by distance. :P

The other thing to attempt is to make sure that I am correct in assuming that a Null Value is causing the problem.
Try adding above line 54:
Expand|Select|Wrap|Line Numbers
  1. If IsNull(Me.SerialNo) then
  2.   Msgbox "Me.SerialNo is Null",vbexclamation
  3. End If
If you get the msgbox then a Null is indead the source of the problem.
Feb 1 '11 #12
TheSmileyCoder
2,322 Expert Mod 2GB
I would suggest reading this great articly by one of our experts:
Debugging VBA
Used correctly you can save loads of time, by knowing how to properly debug.
Feb 1 '11 #13
swen
18
Thank you for the article info... very informative.

I inserted the "if null" statement prior to line 54... It blows past the new "if null" statement with out giving the msgbox statement and then errors out with the same debug statement on the same line of code.

The DB is too large (compressed) to attach or email at this time. I'll try to rip out all but this section.

I appreciate all the help you are providing, everything helps.
Feb 1 '11 #14
swen
18
New development (realization)...
As I was ripping out this section of the DB to attach and verifying all the appropriate tables, qrys, etc. are intact. I ran the report with arbitrary criteria in ALL the fields of the "RunRPT" form for this report.

Guess what... I got the same debug msg (previous in the string) as if the criteria fields were blank.

I verified that the arbitrary info was/not in the table. It seems as though, regardless if there is criteria entered, if the qry/sql retrieves “0” records, this debug error occurs.

If this is plausible, how do I fix this? Do I need to start a new string for this?

All info is appreciated.
Feb 1 '11 #15
swen
18
Attached is the rip out of the DB.
Form "RunRPT" launches several reports.
The "Report Type" on RunRPT (for this string) is "Serial No(s) Checked Out"

Please let me know your thoughts and possible solutions. ALL are welcome.
Attached Files
File Type: zip MC2_ripout.zip (626.5 KB, 89 views)
Feb 1 '11 #16
Thanks for info..
Feb 2 '11 #17
TheSmileyCoder
2,322 Expert Mod 2GB
Your control SerialNo has the same name as its controlsource. Now Access defaults to giving controls the same names as their controlsource, which can cause alot of grief. I changed the NAME of the CONTROL from SerialNo to tb_SerialNo (tb for textbox) and the report ran fine.

EDIT: Seems I jumped the gun, still having issues. Will Look into it more.
Feb 2 '11 #18
TheSmileyCoder
2,322 Expert Mod 2GB
I have looked at it and still can't seem to wrap my head around it. I don't know why access wants to format the detail when there is no detail. Its seems that the error message only occurs when you have no records (which makes sense, thats when the textbox has no value.)

So if all else fails, ignore it. Replace the line 54 with this:
Expand|Select|Wrap|Line Numbers
  1.         'Ignore the error, and proceed.
  2.          'The error is still recorded,
  3.          'which is why we can see it in err.Number
  4.         On Error Resume Next
  5.         lngLast = Nz(Me.tb_SerialNo, -10)
  6.         If err.Number = -2147352567 Then
  7.             'Empty detail, no need to proceed
  8.             Me.LineSkipper.Visible = False
  9.             'Resume normal error handling
  10.             On Error GoTo 0
  11.             Exit Sub
  12.         End If
  13.  
  14.         If err.Number <> 0 Then
  15.             'Another unexpected error occured
  16.             MsgBox "Error [" & err.Number & "] occured." & vbNewLine & vbNewLine & err.Description, vbExclamation + vbOKOnly
  17.         End If
  18.  
  19.         'Resume normal error handling
  20.         On Error GoTo 0
Feb 2 '11 #19
swen
18
Thank you. Thank you for ALL your help.

This code works. Now I can review other requested changes for this DB.

I will review ALL the reports and forms for the use of the same name for the Control Name / controlsource. This may explain some other periodic glitches that have occurred with this DB.
Feb 2 '11 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Ken | last post by:
I created a global.css file which includes this script: div.printbreak {page-break-after: always} In the HTML script I have: <div class=printbreak> .... </div>
1
by: Yaro | last post by:
Hi We want to create case-insensitive database (DB2 8.2.2 Win) . I found information we need create custom collating sequence and create database with this sequence but I can't find informations...
4
by: blee456 | last post by:
I have to create an attendance list for a meeting that will have attendees that are both on the committee and non member participants. My thinking is to create a form that has the member names...
7
by: urban.widmark | last post by:
Hello We are having some problems with triggers, sequences and union all in V8 on code that worked fine in V7. Was wondering if someone else has seen this and/or knows what to do. A trigger...
4
by: jpierson | last post by:
Hi, I'm trying to simulate a break sequence to a serial device ctrl + pause/break I tried it with limited succcess using this SendKeys.SendWait("^{BREAK}") I'm putting this code under a...
1
by: jferrara | last post by:
How do I create a unique id (sequence number) on an existing table via a query.
5
by: Santy | last post by:
I am running my application on Windows. Developed in C++. The DB2 V8 database is installed on MVS mainframes. DB2 Client is installed on Windows. Currently i am getting error as follows :...
4
by: f5leeba | last post by:
I am calling to a large string that is separate paragraphs. I just don know how to put line breaks in flash actionscript. Can anyone help me? example tLabel.text = "blah blah blah blah (then a...
1
by: jakdjak1 | last post by:
how can i create a line break so that actionscript reads it. i am using variable dynamic text boxes which are then scripted into an email script. The basic script i'm using is: on (release)...
2
by: mfuentes74 | last post by:
Hi! I need help I have a report in Access 2007 and I need to insert a page break after every operator id (kn028mf) the first five characters are the same only the last two change, I have tired...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.