Select Case not working

Robert M

Registered User.
Local time
Today, 11:03
Joined
Jun 25, 2009
Messages
153
I am developing a program that takes a length of a word and depending on the length will enter the number of letters in the word into the "LtrCode" Field. However, in running the program, it works well until this point.

WrdLen = Len(Wrd)
MsgBox "WrdLen = " & WrdLen
'I am able to get the length of the word which in this case is 3
Select Case WrdLen
Case WrdLen = 1
RTarget("LtrCode") = 1
Case WrdLen = 2
RTarget("LtrCode") = 2
Case WrdLen = 3 'At this point I Try to update the database to add the new data.
RTarget.AddNew
RTarget("Ltr") = Wrd
RTarget("LtrCode ") = 3
RTarget.Update
Case WrdLen = 4
RTarget("LtrCode") = 4
End Select

As the last part I have a MsgBox "LtrCode = " & RTarget("LtrCode")
and a MsgBox "Ltr = " & RTarget("Ltr")

When the program runs I get a return of
LtrCode = 0
Ltr =

What am I doing wrong?
I have two database an RSource that has the full sentence and an RTarget that breaks down the sentence into words and letters.

Anyhelp in this would be greatly appreciated.

Thank you for your time and help in this matter.

Robert M
 
Robert hi,

The first thing i would say is you do not need to use WrdLen = in your case statements. Case 1, Case 2 etc is the correct format (not sure if WrdLen = 1 is acceptable or not)

What error message are you getting?

I take it you have referenced the table RTarget earlier in your coding (or is RTarget a variable representing your table?). Either way just typing a table name and .AddNew will not do anything (in fact i think it should error out).
The normal way to manually add data to a table is to create an SQL string and use the RunSQL method of the Docmd command (DoCmd.RunSQL). The SQL string would follow the following format:

"INSERT INTO TableName ( Field1, Field2, Field3, etc )
VALUES (Value1,Value2, Value3, Etc);"
 
You seem to assume that after the .Update the record pointer remains on the just-added record of the recordset. That is not necessarily the case.

rst.Bookmark=rst.LastModified should put the pointer at the last modified record of recordset rst.

I do not quite see why you dive into the recordset again, since you do have the values you just put in there yourself. And I agree with
Isskint - why bother with recordsets?
 
You seem to assume that after the .Update the record pointer remains on the just-added record of the recordset. That is not necessarily the case.

rst.Bookmark=rst.LastModified should put the pointer at the last modified record of recordset rst.

spikepl, i wondered if he was using a recordset but he refers to RTarget and RSource as databases so i assumed he meant tables. However Robert, if you are using a recordset copy in your code then spikepl's post is more beneficial to you
 
I use recordsets as that is what I learned in my self teaching and help from others. And yes I ment tables. Sorry about that.
I'll study and work out what Isskint and spikepl suggest when I understand how it works. Thank you both for your help with this matter. I'll post here to let y'all know if it works or not.

Robert M
 
Why are you storing the Length of an existing piece of data in another field to begin with? Is there something you plan to do with it after it is stored? What is the ultimate goal here?
 
Greetings Beetle. My hobby is solving Cryptoquotes in my daily paper, that is where the editor(s) of the puzzle take a famous quote and substitute one letter for another. What my ultimate goal is to get a instants count of 1,2,3, and 4 letter words as well as double letters. At present I do everything manually which is difficult and problematic if I make a mistake. Hence trying to get the computer/database to do most of the work of breaking down the quote.
Isskint and spikepl; As to my problem of not showing the fields properly. The problem was not in the "RTarget("Lst") but in the Select Case section. It should be Case "#" and not Case WrdLen = "#" I made those changes and ran the program with the fields still showing nothing, but when I looked at the table. I had about 25 records of the same "Now" word and the LtrCode "3". Now to the next step of breaking that word down to the single letter and making sure to catch the double letter.

Thanks for all your help.
 
I don't see why you need to store the Length in a field for that. Assuming the quotes are already broken down to individual words in separate rows, then a simple calculated field in a query will give you the Length.

TheLength:Len([WordField])

As far as getting double letters, I would write a function for that (or search for an existing one on the www). The specifics of the function will depend on the specifics of your requirements, for example;

Do you need to know if the word has more than one occurence of double letters (I would assume so)?

Do you need to know the position of the double letters within the string?
 

Users who are viewing this thread

Back
Top Bottom