A Microsoft Office (Excel, Word) forum. OfficeFrustration

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   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Problem Generating Key = reprise



 
 
Thread Tools Display Modes
  #1  
Old March 22nd, 2010, 08:08 PM posted to microsoft.public.access.gettingstarted
Wes[_3_]
external usenet poster
 
Posts: 6
Default Problem Generating Key = reprise

has anybody had a chance to take a look at my posting on 3/19 at 8:13 P.M.

I find it strange that I get a space added to my variable

After retrieving the highest key, I pick up the last 4 characters and add 1

intNewKey = Int(Mid(strMax, 3, 4)) + 1 ' pick up the last 4 bytes and
increment

[ IntNewkey 1003 ]


I then have to convert it back to a string to create the new key

strNewKey = Str(intNewKey) ' cast to string

when I do, the variabel has a blank placed in the first position

[ StrNewKey " 1003" Notice the leading space ]


Is there something I am doing incorrectly here, is this the way it is
supposed to work?

I have done some research and a lot of testing, and it always appears to
work like this.

thanks

Wes
  #2  
Old March 22nd, 2010, 09:08 PM posted to microsoft.public.access.gettingstarted
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default Problem Generating Key = reprise

According to the Help file entry for the Str function "When numbers are
converted to strings, a leading space is always reserved for the sign of
number. If number is positive, the returned string contains a leading space
and the plus sign is implied."

Try:

strNewKey = Format(CInt(Right(strMax, 4) + 1, "0000")

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Wes" wrote in message
...
has anybody had a chance to take a look at my posting on 3/19 at 8:13 P.M.

I find it strange that I get a space added to my variable

After retrieving the highest key, I pick up the last 4 characters and add
1

intNewKey = Int(Mid(strMax, 3, 4)) + 1 ' pick up the last 4 bytes and
increment

[ IntNewkey 1003 ]


I then have to convert it back to a string to create the new key

strNewKey = Str(intNewKey) ' cast to string

when I do, the variabel has a blank placed in the first position

[ StrNewKey " 1003" Notice the leading space ]


Is there something I am doing incorrectly here, is this the way it is
supposed to work?

I have done some research and a lot of testing, and it always appears to
work like this.

thanks

Wes



  #3  
Old March 22nd, 2010, 09:11 PM posted to microsoft.public.access.gettingstarted
XPS350
external usenet poster
 
Posts: 69
Default Problem Generating Key = reprise

On 22 mrt, 21:08, Wes wrote:
has anybody had a chance to take a look at my posting on 3/19 at 8:13 P.M..

I find it strange that I get a space added to my variable

After retrieving the highest key, I pick up the last 4 characters and add 1

intNewKey = Int(Mid(strMax, 3, 4)) + 1 *' pick up the last 4 bytes and
increment

[ *IntNewkey 1003 *]

I then have to convert it back to a string to create the new key

strNewKey = Str(intNewKey) * * * * * * *' cast to string

when I do, the variabel has a blank placed in the first position

[ * StrNewKey " 1003" * Notice the leading space ]

Is there something I am doing incorrectly here, is this the way it is
supposed to work?

I have done some research and a lot of testing, and it always appears to
work like this.

thanks

Wes


I cannot exactly figure out what is wrong with your code. I do know
Int isn't the right function to use. It cuts off the decimal part.

Access is rathet tolerant, so this code will do:

Dim Newkey As String

Newkey = Format(Mid(strMax, 3, 4) + 1, "0000")

Debug.Print Left(strMax, 2) & Newkey



Groeten,

Peter
http://access.xps350.com
  #4  
Old March 22nd, 2010, 09:17 PM posted to microsoft.public.access.gettingstarted
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Problem Generating Key = reprise

On Mon, 22 Mar 2010 16:08:45 -0400, Wes wrote:

I then have to convert it back to a string to create the new key

strNewKey = Str(intNewKey) ' cast to string

when I do, the variabel has a blank placed in the first position

[ StrNewKey " 1003" Notice the leading space ]


Is there something I am doing incorrectly here, is this the way it is
supposed to work?


Try using a negative number. You'll see that it comes out as

"-1003"

It's leaving a space for the sign.

You can use Trim(Str(intNewKey)) to trim off the leading blank.
--

John W. Vinson [MVP]
  #5  
Old March 23rd, 2010, 12:49 AM posted to microsoft.public.access.gettingstarted
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default Problem Generating Key = reprise

"Wes" wrote in message
...
has anybody had a chance to take a look at my posting on 3/19 at 8:13 P.M.

I find it strange that I get a space added to my variable

After retrieving the highest key, I pick up the last 4 characters and add
1

intNewKey = Int(Mid(strMax, 3, 4)) + 1 ' pick up the last 4 bytes and
increment

[ IntNewkey 1003 ]


I then have to convert it back to a string to create the new key

strNewKey = Str(intNewKey) ' cast to string

when I do, the variabel has a blank placed in the first position

[ StrNewKey " 1003" Notice the leading space ]


Is there something I am doing incorrectly here, is this the way it is
supposed to work?

I have done some research and a lot of testing, and it always appears to
work like this.



Use Cstr() instead of Str() -- and CInt() instead of Int():

intNewKey = CInt(Mid(strMax, 3, 4)) + 1
strNewKey = CStr(intNewKey)


--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

  #6  
Old March 23rd, 2010, 11:34 AM posted to microsoft.public.access.gettingstarted
BruceM via AccessMonster.com
external usenet poster
 
Posts: 448
Default Problem Generating Key = reprise

I replied about 11 hours before you made this posting. Aside from the issues
raised here, if the first two digits are always the same you can just append
them before the incremented number for display purposes. If they are
intended to represent the year you need to make provisions to change the
leading numbers next year, and (presumably) to restart the incrementing
numbers at the desired value. Your code as written in the original thread
will do neither that I can see.

Wes wrote:
has anybody had a chance to take a look at my posting on 3/19 at 8:13 P.M.

I find it strange that I get a space added to my variable

After retrieving the highest key, I pick up the last 4 characters and add 1

intNewKey = Int(Mid(strMax, 3, 4)) + 1 ' pick up the last 4 bytes and
increment

[ IntNewkey 1003 ]

I then have to convert it back to a string to create the new key

strNewKey = Str(intNewKey) ' cast to string

when I do, the variabel has a blank placed in the first position

[ StrNewKey " 1003" Notice the leading space ]

Is there something I am doing incorrectly here, is this the way it is
supposed to work?

I have done some research and a lot of testing, and it always appears to
work like this.

thanks

Wes


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...arted/201003/1

 




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:55 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.