Split Text into different lengths in Access 2010 - ms-access

I am currently working on a database in access 2010 that will scan a barcode in PDF147 format.
Basically what the idea is to take the barcode information and split it into the different text boxes of the form.
Ex:
SRGTR17385JOHN DOE DASD17366M
From there I would want to take characters 10-20 and apply it to the first name text-box, then take characters 21-30 and apply it to the last name text box, lastly take the 40th character and apply it to the middle initial text box.
Hope this was specific enough.

If you are obtaining the barcode info from a table, the following query will split out the pieces:
SELECT Table1.BARCODE, Left([BARCODE],10) AS BCOnly, Mid([barcode],11,10) AS FirstName, Mid([barcode],21,10) AS LastName
FROM Table1;
If you want VBA code:
Me.txtBarcode = Left([RS!BARCODE],10)
Me.txtFirstName = Mid([RS!barcode],11,10)
Me.txtLastName = Mid([RS!barcode],21,10)

Related

Microsoft SSRS: How to make horizontal flowing fill-in text

Apologies if this has been asked before, I did look around but I'm new to SSRS and I might not know the right keywords to find what I'm looking for.
I am trying to make a new report with a couple of sentences like:
The purpose of this report is to determine an academic plan for student __________, by listing all the courses they will take.
I would like this to display in my report "just like" a paragraph of text, except that I would like the blank filled in with the student's name.
I understand how to do "basic" textboxes and how to bind values to them.
But how to I get a textbox that knows to expand horizontally until it reaches the end of the line, and then continues on the next line? If this was HTML (with some binding libraries like Knockout), I'd stick it all in a <p>, like:
<p>The purpose... <span data-bind="studentName" />, by listing ... </p>
You need to use placeholders, they will do exactly what you want.
Create a text box with the full sentence, then at the position where you want the student name to appear, right-click on the actual text and choose 'create placeholder'.
Once the placeholder is visible, right-click and choose properties, then just set the value to whatever you want.
The placeholder is like an inline textbox, you can set it to be the contents of a field or an expression, give it it's own formatting etc...
If you need a field in a text box with static text, you'd put the text in quotes and use the & to combine them
="The purpose of this report is to determine an academic plan for student " & Fields!NAME.Value & " by listing all the courses they will take."
Text boxes don't expand horizontally though. The text will take up as much room in the text box as it can and then will make a new line in the text box - expanding vertically.
Hoping you are using BI Studio to do this.
I am assuming that your underlying query just produces one value called FieldName and your data source is called DataSource. The text will wrap to your textbox but you can add in a vbCrLf if you want to force linebreak. Concatenating strings you can use + or &.
In your textbox make a formula and set it to:
="First part of string "+First(Fields!FieldName.value, "DataSource")+" rest of sentence"+vbCrLf+"more string"

Creating a percentage in an expression

Would like to have some text in my report like the following where the percentage is based on an expression. I would like to know how to work out the percentage.
60% of letters were sent with a first class stamp
This is an example of the figures I'm working with
First Class 300
Second Class 150
Other 50
The fields used are 'StampType' and 'RefNo'. The totals are gathered by a count on the 'RefNo'
To do this, do the following steps.
First, add a new Text Box to the report. Click inside the text box so the cursor shows inside. Right-click and choose Create Placeholder.... Enter the following expression for the Value field.
=Lookup("First Class", Fields!StampType.Value, Fields!RefNo.Value, "ReportMain") / Sum(Fields!RefNo.Value, "ReportMain")
This assumes the dataset name that is returning your data is named ReportMain. Change this if needed.
This looks up the First Class RefNo value from the dataset, and then divides that by the total of the RefNo in the dataset.
Go to the Number section of the dialog, change the Category to Percentage. Adjust the Decimal places to your liking. Click OK.
Type the text you want to follow that value after the placeholder (not in the placeholder) in the text box. Like this:
Preview the report, and you should have what you need.

Text Box Formatting

How do I display address values in one row in a Text Box?
Currently values are appear as multiple rows one under another for example:
5,Irivine Place
po box 2345
usa
I'm looking for something like:
5,Irivine Place,po box 2345,usa
If your address is one row in the database then linefeeds must also be being stored. You need to replace these with something else -i.e. a ", " e.g.
=Replace(Fields!Address.Value,VBCRLF,", ")
You would need to get rid of the final ", " in the line so it then becomes:
LEFT(Replace(Fields!Address.Value,VBCRLF,", "),LEN(Replace(Fields!Address.Value,VBCRLF,", ")-2)
Of course you will need to substitute VBCRLF with whatever linefeed character your database is using.

Way to add a calculated number of X's to a form input?

I have certain product codes with varying number of letters/digits e.g. 53HD6J, HH88WBD3 (varies between 5 to 10 letters/digits). In order for our barcode to scan these correctly there has to be 13 letters/digits. I don't want to make the user to input -XXXX after each code but rather have Access calculate the difference between 13 and the length of the code and fill the remaining with a X's. Is this possible either by vba or and expression?
I currently am using about 6 IIFs in one formula to fill remaining blanks with X's but hoping there is an easier way.
I have a form to enter in the batch number (product code). Once that form is submitted it links to a report that is printed. On the report are those batch numbers (53HD6J, HH88WBD3). The spot I want to have this feature is in a text box right next to the codes where Access determines the length of the codes and computes the remaining X's to add. This is in barcode font so this text box is where the 53HD6JXXXXXXX would go. Hope that clears it up!
So I have that part figured out. My problem now is my barcode font reads the text no matter what and translates it still so barcode shows up when the batch number is blank (I have four spots for batch codes to be inputted). So what I had before was =IIf([Text31]="",""&[Text31]&"","") which seemed to work. Hopefully I can continue this with the new formula. If that's unclear let me know.
**(The "" & & "" is so the barcode can be scanned).
My formula was wrong right above with the IIf. I figured it out! Forgot I had used ' Like "*" '. Thanks!
You can do what you want with String() and Left().
Here is an example from the Access Immediate window:
product_code = "53HD6J"
? product_code & String(13, "X")
53HD6JXXXXXXXXXXXXX
? Left(product_code & String(13, "X"), 13)
53HD6JXXXXXXX
Based on the update to your question, I think you can use that approach for the Control Source of a text box where you want to display the "expanded" product code.
Pretend your report has a text box named txtProduct_code where the raw product code, such as 53HD6J, is displayed. And there is a second text box where you want to display that value with the required number of X characters (53HD6JXXXXXXX).
Use this as the Control Source property of that second text box:
= Left([txtProduct_code] & String(13, "X"), 13)
Alternatively, you could make it a field expression in the report's Record Source query.
SELECT
product_code,
Left(product_code & String(13, "X"), 13) AS expanded_product_code
FROM YourTable;

MS Access VBA Cross tab report legend sort order

The problem is hard to explain ,
I have an access report with a stacked bar chart to show the percentage fills over time like the one in this example : Click here
The legend for the chart i have is a number followed by the name, for e.g
1-Mango
2-Apple
3-Banana
etc
I want to sort this according to the above format but when i have more than 10 items the 10-Pineapple comes before 1-mango when it should appear after 9-somefruit .
The underlying query for the access report uses a Cross Tab query in which the items are created as
Column heading:[PrefixPriorityNumber]&"-"&[FruitName]
I even used the Sort:Ascending but it still doesnt affect my custom ordering that i wanted to show.
I also tried to google "sorting alpha numeric strings" but this is clearly more than that.Any assistance is appreciated
The problem is you are getting a text sort. You need to format the prefix number.
Column heading: Format([PrefixPriorityNumber], "00") & "-" & [FruitName]
Either use another digit, as Remou suggests (01 instead of 1) or start using letters. A > 9, B > A, etc.