473,387 Members | 1,483 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,387 software developers and data experts.

Inserting a space into a string

Hi there,
I'm building an Access database and using VBA to generate Microsoft Word
mailings for customers. It's all going fine so far. However, a variables
named ParcelID, a ten-digit string such as TQ03409954, needs to be split into
SHEET ID (the first six characters) and PARCEL ID (the last 4) e.g. TQ0340
9954. Can anyone help me? I'm messing around using For loops and the Split()
function, but to no avail.
Many thanks,
Andy
Reading, UK
Jul 21 '06 #1
7 1438
"Andy C Matthews" wrote ...
a ten-digit string such as TQ03409954, needs to be split into
SHEET ID (the first six characters) and PARCEL ID (the last 4) e.g. TQ0340
9954. Can anyone help me? I'm messing around using For loops and the
Split()
function, but to no avail.
Dim CombinedID As String
Dim SheetID As String
Dim ParchelID As String

CombinedID = "TQ03409954"

SheetID = Left(CombinedID, 6)
ParcelID = Right(CombinedID, 4)
Hope that helps..

Regards

Rob

Jul 21 '06 #2
I should have added..

Dim NewCombinedID As String

NewCombinedID = SheetID & " " & ParcelID

My apologies..

Rob
Jul 21 '06 #3
Thanks Rob, that's really helpful.
This is the function I've come up with using it:
Public Function splitpid(CombinedID As String)

Dim SheetID As String
Dim ParcelID As String

SheetID = Left(CombinedID, 6)
ParcelID = Right(CombinedID, 4)

End Function
How can I pass the SheetID and ParcelID back into each stage of the
following loop: (snippet of code follows)

'Filling objWord object with data
With objWord
.Visible = True
.Documents.Open (strDocPath)

'Inserting SBI
.ActiveDocument.Bookmarks("bmSBI").Select
If IsNull(Forms!frmMainData!SBI) Then SBIno = "" Else: SBIno =
(CStr(Forms!frmMainData!SBI))
.Selection.Text = SBIno

'Navigate to first record (field)
Forms!frmMainData!subFields.SetFocus
DoCmd.GoToRecord , , acFirst
'Jump to each bookmark in the word doc and insert corresponding
DB field data
'Checks to make sure fields aren't Null before passing data to
Word document

'Navigate to 1st record (field)
.ActiveDocument.Bookmarks("bmOldPID").Select
If IsNull(Forms!frmMainData!subFields!NewParcelID) Then
OldPID1 = "" Else: OldPID1 = (CStr(Forms!frmMainData!subFields!NewParcelID))
OldPID1 = OldPID1 & "Hello"
.Selection.Text = OldPID1

.ActiveDocument.Bookmarks("bmNewPID").Select
If IsNull(Forms!frmMainData!subFields!OldParcelID) Then
NewPID1 = "" Else: NewPID1 = (CStr(Forms!frmMainData!subFields!OldParcelID))
.Selection.Text = NewPID1

.ActiveDocument.Bookmarks("bmFieldSize").Select
If IsNull(Forms!frmMainData!subFields!FieldSize) Then
FieldSize1 = "" Else: FieldSize1 =
(CStr(Forms!frmMainData!subFields!FieldSize))
.Selection.Text = FieldSize1

'Navigate to 2nd record (field)
Forms!frmMainData!subFields.SetFocus
DoCmd.GoToRecord , , acNext

.ActiveDocument.Bookmarks("bmOldPID2").Select
If IsNull(Forms!frmMainData!subFields!New

"Rob Meade" wrote:
"Andy C Matthews" wrote ...
a ten-digit string such as TQ03409954, needs to be split into
SHEET ID (the first six characters) and PARCEL ID (the last 4) e.g. TQ0340
9954. Can anyone help me? I'm messing around using For loops and the
Split()
function, but to no avail.

Dim CombinedID As String
Dim SheetID As String
Dim ParchelID As String

CombinedID = "TQ03409954"

SheetID = Left(CombinedID, 6)
ParcelID = Right(CombinedID, 4)
Hope that helps..

Regards

Rob

Jul 21 '06 #4
"Andy C Matthews" wrote ...
Thanks Rob, that's really helpful.
You're welcome.
How can I pass the SheetID and ParcelID back into each stage
Change your function a little...

Public Function SplitPID(ByVal PID As String, ByRef SheetID As String, ByRef
ParcelID As String)

sheetID = Left(pid, 6)
parcelID = Right(pid, 4)

End Function
The above function will populate 2 variables DIM'd in the class calling this
function (they need to be called sheetID and parcelID in this example)

It might go something like this...

Dim PID As String
Dim SheetID As String
Dim ParcelID As String

' I clear these here just to point out that you might want to do this as you
are going to be looping through stuff...
SheetID = ""
ParcelID = ""

' call the function to populate the variables
SplitPID(PID, SheetID, ParcelID)
All you need to do is place the variables being cleared code, and the
function call in your loop and then use the variables (SheetID and ParcelID)
appropriately in the rest of your code..

Hope this helps...

Rob

Jul 21 '06 #5
Rob Meade wrote:
Public Function SplitPID(ByVal PID As String, ByRef SheetID As String, ByRef
ParcelID As String)

sheetID = Left(pid, 6)
parcelID = Right(pid, 4)

End Function
Just a little nit picking: if your method is not going to return a
value, you should use a Sub instead of a Function.

Jul 21 '06 #6

"Andy C Matthews" <An***********@discussions.microsoft.comwrote in message
news:52**********************************@microsof t.com...
:
: "Rob Meade" wrote:
:
: "Andy C Matthews" wrote ...
: >
: a ten-digit string such as TQ03409954, needs to be split into
: SHEET ID (the first six characters) and PARCEL ID (the last 4) e.g.
: TQ0340 9954. Can anyone help me? I'm messing around using For loops
: and the Split() function, but to no avail.
: >
: Dim CombinedID As String
: Dim SheetID As String
: Dim ParchelID As String
: >
: CombinedID = "TQ03409954"
: >
: SheetID = Left(CombinedID, 6)
: ParcelID = Right(CombinedID, 4)
: >
: >
: Hope that helps..
: >
: Regards
: >
: Rob
: >
: Thanks Rob, that's really helpful.
: This is the function I've come up with using it:
:
:
: Public Function splitpid(CombinedID As String)
:
: Dim SheetID As String
: Dim ParcelID As String
:
: SheetID = Left(CombinedID, 6)
: ParcelID = Right(CombinedID, 4)
:
: End Function

Based on the title of your post, I gather you want string "SSSSSSPPPP" to be
converted into "SSSSSS PPPP". Correct? If so, you can the mondify the
function as shown here:
Public Function splitid(CombinedID As String) As String
splitID = Left(ComninedID, 6) & " " & Right(CombinedID, 4)
End Function

: How can I pass the SheetID and ParcelID back into each stage of the
: following loop: (snippet of code follows)
:
:
: 'Filling objWord object with data
: With objWord
: .Visible = True
: .Documents.Open (strDocPath)
:
: 'Inserting SBI
: .ActiveDocument.Bookmarks("bmSBI").Select
: If IsNull(Forms!frmMainData!SBI) Then SBIno = ""
: Else: SBIno =
: (CStr(Forms!frmMainData!SBI))
: .Selection.Text = SBIno
:
: 'Navigate to first record (field)
: Forms!frmMainData!subFields.SetFocus
: DoCmd.GoToRecord , , acFirst
:
:
: 'Jump to each bookmark in the word doc and insert corresponding
: DB field data
: 'Checks to make sure fields aren't Null before passing data to
: Word document
:
: 'Navigate to 1st record (field)
: .ActiveDocument.Bookmarks("bmOldPID").Select
: If IsNull(Forms!frmMainData!subFields!NewParcelID) Then
: OldPID1 = "" Else: OldPID1 =
: (CStr(Forms!frmMainData!subFields!NewParcelID))
: OldPID1 = OldPID1 & "Hello"
: .Selection.Text = OldPID1
:
: .ActiveDocument.Bookmarks("bmNewPID").Select
: If IsNull(Forms!frmMainData!subFields!OldParcelID) Then
: NewPID1 = "" Else: NewPID1 =
: (CStr(Forms!frmMainData!subFields!OldParcelID))
: .Selection.Text = NewPID1
:
: .ActiveDocument.Bookmarks("bmFieldSize").Select
: If IsNull(Forms!frmMainData!subFields!FieldSize) Then
: FieldSize1 = "" Else: FieldSize1 =
: (CStr(Forms!frmMainData!subFields!FieldSize))
: .Selection.Text = FieldSize1
:
: 'Navigate to 2nd record (field)
: Forms!frmMainData!subFields.SetFocus
: DoCmd.GoToRecord , , acNext
:
: .ActiveDocument.Bookmarks("bmOldPID2").Select
: If IsNull(Forms!frmMainData!subFields!New
:
Where precisely in this code snippet do you want this conversion to occur?
Ralf


Jul 21 '06 #7
"Chris Dunaway" wrote ...
Just a little nit picking: if your method is not going to return a
value, you should use a Sub instead of a Function.
I thought about that as I was posting, but had a mental block and couldn't
remember if I could use the ByRef's with a sub or not etc...too hot hear to
open up Visual Studio and try it! Plus, my second reply to the OP's post
was aimed at returning a new combined string..

Either way - my bad...

Rob
Jul 21 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mechphisto | last post by:
I'm using a textarea to insert some notes into a database. It's inserting the complete result into the mySQL table including the linebreaks...and not as a visible symbol but an actual linebreak. If...
1
by: Chris Sharman | last post by:
Writing a form, several questions have got a list of checkboxes, with associated descriptions (mostly one word), all on a line. Eg: Describe yourself: Fat Hairy Ugly Wears glasses. I want to...
4
by: epaetz | last post by:
I'm doing a bcp out of a table to a file. Some of the fields in a record may have an empty string. When I bcp out to the file and examine it, the fields that have an empty string in the database...
4
by: Mesan | last post by:
Here's the question: How do you get DB2 to update a char(n) field with multiple spaces right next to each other without having the additional spaces being omitted? Here's the background: We...
2
by: altergothen | last post by:
Hi there I am a newbie to ASP.Net - Please Help! I am trying to insert the values of my variables into a database. If I try the following it works perfectly: string insertQuery = "INSERT into...
8
by: barry | last post by:
Have tried a number of things including space(n) in front of the string but when the DropDownList is shown the spaces have apparently been trimmed. Is this something that would have to be done in a...
7
by: Astra | last post by:
Hi All Can you please help me with a few queries on adding a header line and padding rows out. I apologise profusely for not providing the DDL for this, but I don't have it. All I have is...
4
by: irsmartt | last post by:
How can I allow a user (in a command prompt) to enter a string of characters and put spaces in it? I use Dev C++. Example: char google; cin>> google; Whenever I try this and output the...
20
by: alice | last post by:
I'm doing some text swapping with javascript, got it working fine, but I would like the line to have line breaks and being a beginner, I don't even know if this is possible. So I have a line like...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.