Avatar of cklosko
cklosko
 asked on

How do I convert double to string?

I need to auto populate an Id field with 999999991, then 999999992, etc. when an Id is not entered by the user. The Id is text, since the user wants to use a leading 0 in the Id, such as 043-432-098. So, I am converting the text to a double, so as to be able to add 1 (when I used int, I got an overflow error). Then, I need to convert this new number, 999999992, for example, back to a text string. My code looks, as follows:
Dim MaxForcedANumber As String
Dim ANumberDbl As Double

'If ANumber was not entered, force 99999999x
If IsNull(Me.ANumber) = True Then
  'Search for largest A Number in database (forced A Numbers are largest)
  MaxForcedANumber = DMax("ANumber", "tbl_AllClients")
  ANumberDbl = CDbl(MaxForcedANumber) + 1
  Me.ANumber = Mid(ANumberDbl, 1, 3) & "-" & Mid(ANumberDbl, 4, 3) & "-" & Mid(ANumberDbl, 7, 3)
 End If
I get a type mismatch error. What is incorrect?
Microsoft Access

Avatar of undefined
Last Comment
Rey Obrero (Capricorn1)

8/22/2022 - Mon
Gustav Brock

You could use:

  MaxForcedANumber = DMax("ANumber", "tbl_AllClients")
  ANumberDbl = CDbl(MaxForcedANumber) + 1
  Me.ANumber = Format(ANumberDbl, "000\-000\-000\-")

/gustav
ASKER CERTIFIED SOLUTION
Rey Obrero (Capricorn1)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
peter57r

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Gustav Brock

Correction:

  Me.ANumber = Format(ANumberDbl, "000\-000\-000")

/gustav
Rey Obrero (Capricorn1)

peter is right,

Anumber is stored  with format 043-432-098 if 99999999x is not yet on the table


This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23