tonik
01-25-2006, 08:54 AM
Any genius’ out there that can help me with this one?
I'm using Access 2002 on WinXP.
What I have is a document ID number system. The ID can be formatted in the following ways:
000.000
000.000.00
000.000.0000
What I’m running into is when the DLookup finds a match that is greater than 7 characters I get a type mismatch error. I thought that it may be looking at it as a number, so I’ve added a line of code that converts it back into a string if that was the case. I still get the error either way. Here’s the code:
Private Sub cmbCatNo_AfterUpdate()
On Error GoTo Err_cmbCatNo_AfterUpdate
Dim strCatNo As String
Dim strSecNo As String
Dim strSeqNo As String
Dim dblConvertNo As Double
'Three digit category number pulled from a control on the form.
strCatNo = [Forms]![frmDocumentNamingForm]![cmbCatNo]
'First number in sequence for the secondary number control.
strSecNo = ".001"
'First concantinated sequence number to compare.
strSeqNo = "" & strCatNo & strSecNo & ""
'Clears secondary number field on form.
[Forms]![frmDocumentNamingForm]![txtSecNo] = ""
'Looks for a match in database to the latest sequenced number. FileID is a string datatype.
Do While DLookup("[FileID]", "DocumentMaster", "[FileID] Like '" & strSeqNo & "*'")
'Converts the string into a decimal and add the next sequenced number.
dblConvertNo = CDbl(strSeqNo) + 0.001
'Reformats the number for comparison.
strSeqNo = Format(dblConvertNo, "000.000")
'Converts the data back into a text string.
strSeqNo = "" & CStr(strSeqNo) & ""
MsgBox strSeqNo
Loop
'If no match is found, it inputs the right three digits of the sequence number into the secondary number control.
[Forms]![frmDocumentNamingForm]![txtSecNo] = Right(strSeqNo, 3)
Exit_cmbCatNo_AfterUpdate:
Exit Sub
Err_cmbCatNo_AfterUpdate:
MsgBox Error$
Resume Exit_cmbCatNo_AfterUpdate
End Sub
I'm using Access 2002 on WinXP.
What I have is a document ID number system. The ID can be formatted in the following ways:
000.000
000.000.00
000.000.0000
What I’m running into is when the DLookup finds a match that is greater than 7 characters I get a type mismatch error. I thought that it may be looking at it as a number, so I’ve added a line of code that converts it back into a string if that was the case. I still get the error either way. Here’s the code:
Private Sub cmbCatNo_AfterUpdate()
On Error GoTo Err_cmbCatNo_AfterUpdate
Dim strCatNo As String
Dim strSecNo As String
Dim strSeqNo As String
Dim dblConvertNo As Double
'Three digit category number pulled from a control on the form.
strCatNo = [Forms]![frmDocumentNamingForm]![cmbCatNo]
'First number in sequence for the secondary number control.
strSecNo = ".001"
'First concantinated sequence number to compare.
strSeqNo = "" & strCatNo & strSecNo & ""
'Clears secondary number field on form.
[Forms]![frmDocumentNamingForm]![txtSecNo] = ""
'Looks for a match in database to the latest sequenced number. FileID is a string datatype.
Do While DLookup("[FileID]", "DocumentMaster", "[FileID] Like '" & strSeqNo & "*'")
'Converts the string into a decimal and add the next sequenced number.
dblConvertNo = CDbl(strSeqNo) + 0.001
'Reformats the number for comparison.
strSeqNo = Format(dblConvertNo, "000.000")
'Converts the data back into a text string.
strSeqNo = "" & CStr(strSeqNo) & ""
MsgBox strSeqNo
Loop
'If no match is found, it inputs the right three digits of the sequence number into the secondary number control.
[Forms]![frmDocumentNamingForm]![txtSecNo] = Right(strSeqNo, 3)
Exit_cmbCatNo_AfterUpdate:
Exit Sub
Err_cmbCatNo_AfterUpdate:
MsgBox Error$
Resume Exit_cmbCatNo_AfterUpdate
End Sub