?
Solved

Take cell out of formula

Posted on 2014-03-07
8
Medium Priority
?
318 Views
Last Modified: 2014-03-10
I am using a formula that takes a number and writes it in letters according to what I have assigned each digit. I now want a button that will reverse it and put the letters back into the original number. Any idea the formula for another button to put it back in numbers? The third field name will be txtOutput2

The formula I am using to write in letters is as follows:

Dim arrayname
Dim i As Long
Dim bNumeric As Boolean
arrayname = Array("q", "w", "e", "r", "t", "y", "u", "i", "p", "a")

bNumeric = True
Me.txtOutput = Null
For i = 1 To Len(Me.txtInput)
    If IsNumeric(Mid(Me.txtInput, i, 1)) Then
    Else
        bNumeric = False
        i = Len(Me.txtInput)
    End If
Next
   

If bNumeric Then
    Me.txtOutput = ""
    For i = 1 To Len(Me.txtInput)
        Me.txtOutput = Me.txtOutput + arrayname(CInt(Mid(Me.txtInput, i, 1)))
    Next
Else
    MsgBox "Non-numeric symbols entered: " & Me.txtInput, vbOKOnly
End If

Me.fldDateUpdated = Now()

Open in new window

0
Comment
Question by:cansevin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 40

Expert Comment

by:als315
ID: 39913126
You can use this function:
Function conv_txt2num(in_str As String) As String
Dim arrayname
Dim i As Long, j As Long, out_str As String, c As String
Dim bNumeric As Boolean
arrayname = Array("q", "w", "e", "r", "t", "y", "u", "i", "p", "a")
out_str = ""
For i = 1 To Len(in_str)
    c = Mid(in_str, i, 1)
    For j = 0 To UBound(arrayname)
        If c = arrayname(j) Then
            out_str = out_str & j
            Exit For
        End If
    Next j
Next i
conv_txt2num = out_str
End Function

Open in new window

Call it like:
Me.txtOutput2 =  conv_txt2num(Me.txtInput)
0
 

Author Comment

by:cansevin
ID: 39913228
At the risk of sounding real stupid... is that something I can copy and past into an "OnClick" event? That is what I am looking for.
0
 
LVL 40

Expert Comment

by:als315
ID: 39913251
You can paste function to module for use anywhere (in queries, on forms, etc). In "OnClick" event you can call function like in sample above:
Me.txtOutput2 =  conv_txt2num(Me.txtOutput)
ConvertNum.accdb
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:cansevin
ID: 39913275
Ok... what field names do I change?

My field names are: The letters I start with is txtOutput and the final numbers are txtOutput2.
0
 

Author Comment

by:cansevin
ID: 39913405
I figued out which to change... but when I click the button, nothing happens. It isn't putting the result in the field. The code I am using is:

Private Sub Command43_Click()

Dim arrayname
Dim i As Long, j As Long, out_str As String, c As String
Dim bNumeric As Boolean
arrayname = Array("q", "w", "e", "r", "t", "y", "u", "i", "p", "a")
out_str = ""
For i = 1 To Len(in_str)
    c = Mid(in_str, i, 1)
    For j = 0 To UBound(arrayname)
        If c = arrayname(j) Then
            out_str = out_str & j
            Exit For
        End If
    Next j
Next i
conv_txtOutput2 = out_str

End Sub

Open in new window

0
 

Author Comment

by:cansevin
ID: 39913421
I will upload the form I am working with. Any chance you can help? Thanks for everything.
form.accdb
0
 
LVL 40

Accepted Solution

by:
als315 earned 2000 total points
ID: 39914272
I prefer to use separate functions (look at Module1), because you can reuse in other cases. Copy Module1 to new DB and you can call this function from any form.
form.accdb
0
 

Author Comment

by:cansevin
ID: 39918027
It worked!!! Thanks... I am going to need help using it on a report.  I will post another question for that.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question