Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing Specific Characters from a String

Status
Not open for further replies.

WAR40K

Technical User
Oct 29, 2003
29
0
0
US
I have a variable getYear in which I would like to store the year as 04 from a string 09/17/04. How would i do this? Can it be done without using the "RIGHT" or "FORMAT" methods?

I keep getting errors with computers that do not have xp installed when I use the "RIGHT" or "FORMAT" methods. I need a workaround.

Thank you
 
What would be wrong with using the "Right" method?

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
I continually get an Object or Library Not Found message on all computers that do not feature the XP version of Windows. An upgrade of VBA or Access did not solve the problem. Any thoughts?
 
Hi,

Is it REALLY a STRING? If you are dealing with a Real Date in MS application, then it REALLY a NUMBER, in which case
Code:
Yr = Format([MyDate], "yy")
or
Yr = Year([MyDate]) - 2000
[code]
BTW, Right & Format are NOT exclusive to XP.  Standard VB for YEARS!

Skip,
[sub]
[glasses] [b][red]Be advised:[/red][/b]  When transmitting sheet music...
[b]If it ain't baroque, don't fax it![/b] [tongue][/sub]
 
yeah, I'm storing it as a string i.e. DIM getYear as String.

then getYear = Right(Cstr(Year(Now())),2)

Then when the event triggers execution, i get a compile error "Object or Library Not Found"

I'm at my wit's end. I figure it should be standard since the method is in the help file, but it still doesn't execute. Should I replace the above with
DIM getYear as Date

Thx
 
Here is the full code, maybe it will help. Note: year is a text field and ccr_no is an integer

Dim email, emailCC, ref, origin, destination, notes, strBody, order, record, part, sn, strSQL As String
Dim rs As Recordset
Dim db As Database
Dim getYear, currYear As String
Dim ccr As Integer

order = Me.work_ord
record = Me.mrf_id
part = Me.part_rec
sn = Me.serial
getYear = Right(CStr(year(Now())), 2)


If warranty = False Then
Exit Sub
Else
'***email recipients***
email = "user@isp.com"
emailCC = "user@isp.com"
ref = "Warranty Repair Review"

'***Set up message body using fields.
strBody = "A new customer service work order " & order & " has been opened. "
strBody = strBody & "Please look at MRF form # " & record & " to review the warranty return. "
strBody = strBody & "Part number Received: " & part
strBody = strBody & " Serial Number: " & sn

'*** send email notificiation
DoCmd.SendObject acSendNoObject, , , email, emailCC, , ref, strBody, True

'***Add new Customer Corrective Action Report
strSQL = "SELECT ccr_no, year FROM WIR"
Set db = CurrentDb()
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
rs.MoveLast
With rs
currYear = .Fields("year")
If currYear = getYear Then
ccr = .Fields("ccr_no") + 1
Else
ccr = 1
End If
End With

createNewCCR:

DoCmd.SetWarnings False
strSQL = "INSERT INTO WIR ( wir_no, corrective_action, customer, part_no, serial_no, compaint, comp_verified, rma ) "
strSQL = strSQL & "SELECT work_ord, sugg_rep, customer, part_rec, serial, discrepancy, verfied, rma FROM MRF WHERE work_ord = " & "'" & Me.work_ord & "'"
DoCmd.RunSQL strSQL

strSQL = "UPDATE WIR SET WIR.ccr_no = " & "'" & ccr & "'" & " WHERE WIR.wir_no = " & "'" & Me.work_ord & "'"
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
End If

errorhandler:
Exit Sub


'****end code****
End Sub
 
Sounds like you have a missing dll.

Reinstall your application.

Skip,
[sub]
[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue][/sub]
 
Do you actually get the error on line...
getYear = Right(CStr(year(Now())), 2)

You realize that
Dim getYear, currYear As String

...means that getYear is defined as a Variant data type which means it becomes what ever data type a variable is assigned to it.

Whether you string the variables on the same line, or on separate lines, you have to specifically assign the datatype - otherwise, it is assigned the datatype variant.

Dim getYear As String, currYear As String

...ditto for the line...
Dim email, emailCC, ref, origin, destination, notes, strBody, order, record, part, sn, strSQL As String


Next are the lines...
Dim rs As Recordset
Dim db As Database


You may run into a problem / conflict between DAO and ADO. (Your code suggest you are using DAO)

I do not mean to be nit-picky -- if your code works, great. But I know that both of the issues I mention can cause code to crash.

Richard


 
Maybe you should instead of:
yeah, I'm storing it as a string i.e. DIM getYear as String.

then getYear = Right(Cstr(Year(Now())),2)

Do like this:
Code:
Dim getYear as Date
Dim Yr as String
getYear = Cstr(Year(Now))
Yr = Format(getYear, "yy")

that would be more along the idea of what Skip originally posted. I am thinking that the problem lies with you using a string to get the date from all that first. Try this method, and see if it works...


Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
Kjv1611,

Tried your method, compile hung up on the "Format(getYear,"yy")". I just removed that functionality as it doesn't affect the day to day operation of the program and will deal with it at some later date. Thank you for your help.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top