Solved

Writing a code in access

Posted on 2014-03-05
12
293 Views
Last Modified: 2014-03-12
I am trying to write a code in access for an assignment for my students. There will be two fields:

field1 is where students enter numbers, long numbers possibly 20 numbers long.

They then hit a button
The button will write the number they entered in field one according to a code of 0=q, 1=w, 2=e, 3=r, 4=t, 5=y, 6=u, 7=i, 8=p, 9=a

The result will appear in field 2.

For example.

field1: 453
after hitting the button field two shows: tyr

Thanks!
0
Comment
Question by:cansevin
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 39908333
Dim arrayname
  Dim  i As Long, field1 As String, field2 As String
  arrayname = Array("q", "w", "e", "r", "t", "y", "u", "i", "p", "a")
  field1 = "453"
  For i = 0 To Len(field1) - 1
    field2 = field2 + arrayname(i)
  Next
  MsgBox field2
0
 
LVL 39

Expert Comment

by:als315
ID: 39908414
I think sample has errors, but it can be corrected:
Dim arrayname
Dim i As Long, field1 As String, field2 As String
arrayname = Array("q", "w", "e", "r", "t", "y", "u", "i", "p", "a")
field1 = "453"
If IsNumeric(field1) Then
    field2 = ""
    For i = 1 To Len(field1)
        field2 = field2 + arrayname(CInt(Mid(field1, i, 1)))
    Next
    MsgBox field2
Else
    MsgBox "Non-numeric symbols entered: ", field1
End If

Open in new window

0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 39908712
thanks als315; I wasn't paying attention :-)
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 39910665
Let me start with an apology.  Please don't be offended.  I've been wanting to say this for some time and it looks like you have your answer so I'll just jump in.

Codes are limited lists of values - area codes, zip codes, department codes, etc.  Or an encrypted value.  During WWII, the British captured an enigma machine and with it were able to decipher the codes the Germans used to encrypt their messages.  "A" code is a member of a set of codes so 203 is the area code for most of Western Connecticut or "F" is the value for female in a list of gender codes, or "a" code could be the entire body of the tokens substituted for letters to encrypt a message.  The Germans used a different code for each day of the week.  So on Monday an "a" is coded as "t", on Tuesday it is "c", on Wednesday it is "x", etc.

Code is what a programmer writes. No article, no trailing s to make it plural.  It is singular and plural and never takes the article "a" although it can take the article "the".  We never say "a code" but we do say "the code".   A programmer might create "a" procedure or "a" function or "a" subroutine but he writes code.  Not "a" code, not "codes".  Just code.
0
 

Author Comment

by:cansevin
ID: 39912525
Thanks guys... appreciate your help. I am sure it is my fault, but I can't get it to work properly. It keeps opening of dialogue box with just the "tyr". I would it to take whatever was in the raw1 field and write it in the code for the saved1. Also note... my students may be entering very long numbers, up to 20 digits long. Not sure if this will affect anything. Thanks for all the help! Pat... very interesting, thanks!

I am using the below code for my on click of the button.

Private Sub Command42_Click()

Dim arrayname
Dim i As Long, raw1 As String, saved1 As String
arrayname = Array("q", "w", "e", "r", "t", "y", "u", "i", "p", "a")
raw1 = "453"
If IsNumeric(raw1) Then
    saved1 = ""
    For i = 1 To Len(raw1)
        saved1 = saved1 + arrayname(CInt(Mid(raw1, i, 1)))
    Next
    MsgBox saved1
Else
    MsgBox "Non-numeric symbols entered: ", raw1
End If

Me.fldDateUpdated = Now()

End Sub
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 39912810
The problem was with your last message box.  You needed to concatenate raw1 using the &.
ConvertNum.accdb
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Accepted Solution

by:
cansevin earned 0 total points
ID: 39912861
Pat, thanks! It is working perfect on yours... on mine... when I hit the button, nothing shows up. The date and time stamp changes correctly but nothing shows up. The code I am using is below (I changed my names to txtInput and txtOutput

Private Sub Command42_Click()

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()
End Sub
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 39912948
I copied the code and pasted it into the database I sent to you and it works fine.

Does the code compile in your database?

Are you sure you are using the correct control names?
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 39913075
Do you realize that you accepted your own answer?
0
 

Author Comment

by:cansevin
ID: 39913086
That's not good... No clue how I pulled that off. I'll try to fix it.
0
 

Author Closing Comment

by:cansevin
ID: 39922911
Thanks! I am an idiot... the table type of that cell was number. Changed to text and it works perfect. Thanks!

I am now going to post a question for a button what will take it out of the letters and back to numbers. Maybe you can help with it.  Thanks for everything this morning.
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 39923566
You accepted your own answer again.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Export  Access Query To Excell 16 45
Run-time error '1004' after second execution of code. 4 38
DSum for Access 6 44
Excess tables to Excel BackUp 3 28
In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now