If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Type Conversion

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-24-04, 14:31
CorvetteAkio CorvetteAkio is offline
Registered User
 
Join Date: Mar 2004
Posts: 3
Type Conversion

I have input boxes that I use to input the selection data that I want (numbers/dates).

My macro opens the template that corresponds to my selection, then saves the file as Date_Block.xls.

The problem that I am running into is that when i do a type conversion to convert my number to a string so that I can use it in a filename, it adds a space to the beginning of the data.

I.E. If I have "SS = 1", then I convert it, it comes out " 1".

Is there a simple way to have it not add the space? Or a simple way to eliminate it? I could add a case structure that would set the string based on the number, but it would have ~60 cases.

Here is the code I am using:

-------------------------------------
Sub Run_Access_Macro()
Dim Sensor As String
Dim StartDate As String
Dim EndDate As String
Dim Block As String
Dim File As String
Dim Template As String

Dim B As Double
Dim S As Double
Dim SS As Double
Dim ES As Double

'Prompt for Block, StartDate, and EndDate
B = InputBox("Please enter block number:", "Access Query")
StartDate = InputBox("Please enter Start Date:", "Access Query")
EndDate = InputBox("Please enter End Date:", "Access Query")

Block = Str(B)

'Set Filename and Template
File = StartDate + "_" + Block + ".xls"
Template = "Template_" + Block + ".xls"

'Open Template
Workbooks.Open Filename:="C:\Life_Test\" + Template

...........

End Sub
Reply With Quote
  #2 (permalink)  
Old 03-25-04, 04:08
DavidCoutts DavidCoutts is offline
Registered User
 
Join Date: Jan 2004
Location: Aberdeen, Scotland
Posts: 1,067
Re: Type Conversion

Hi

Have you tried using the trim comand
i.e. MyString = Trim(MyString)

This should get rid of any spaces at the start or end of the string

Hope this Helps
David
Reply With Quote
  #3 (permalink)  
Old 03-25-04, 11:44
CorvetteAkio CorvetteAkio is offline
Registered User
 
Join Date: Mar 2004
Posts: 3
Re: Type Conversion

Quote:
Originally posted by DavidCoutts
Hi

Have you tried using the trim comand
i.e. MyString = Trim(MyString)

This should get rid of any spaces at the start or end of the string

Hope this Helps
David
It worked.

Thanks!

Jason
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On