By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,855 Members | 1,970 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,855 IT Pros & Developers. It's quick & easy.

Comparing Text Fields in table

P: n/a
Our incident numbering system is based on the following YEAR 05 MONTH
06 NMBR 1234

looks like 05-06-1234

the counter number is manually reset each month and I would like to
make it automatic. I am having trouble with the comparing the old month
stored as two digit number as text with the new two digit month found
using format(date(),"mm")

I am using a seperate table with two fields txtMonthOld and
txtMonthCurrent. My idea was to write the new two digit month in
txtMonthCurrent and then compare the two fields. After the comparison
was made, the two digit month in txtMonthCurrent was then written in
txtMonthOld. If there was a difference, a seperate code that I use to
reset the counter number takes effect. If there is no difference,
nothing happens.

I cannot figure out how to compare the two fields? Any help would be


Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Perhaps this (air):

Private Const cTableWithFieldsToCompare As String = "MyTable"
Private Const cFirstField As String = "txtMonthOld"
Private Const cSecondField As String = "txtMonthCurrent"

Function CompareMe() as Boolean
Dim db As DAO.Database
Dim rec as DAO.Recordset
Dim return as Boolean
'Set Default Return Value to False
return = False
Set db = CurrentDb()
With db
'Open a dynaset (so findfirst method is available)
Set rec = .OpenRecordSet(cTableWithFieldsToCompare, dbOpenDynaset)
With rec
'Populate recordset
'Insert Code here to find the record??
'.FindFirst("ID = " & somevariable)
'Here's the logic to compare the fields
If .Fields(cFirstField) = .Fields(cSecondField) Then
return = True
End If
End With
End With
'Clean up
Set rec = Nothing
Set db = Nothing
'Set return value
CompareMe = return
End Function

This function returns true if the fields match, false if they don't.
Note that I've only stubbed out code to find a particular record. I
would envision a parameter to the function (i.e. see somevariable
above) that provides the key to the record you need.

(feel free to email me for clarification at j{deleteme]meredith AT g
MAil DOT com)

Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.