index > Visual Basic for Applications (VBA) > Type Mismatch

Type Mismatch

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?? 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??e 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?? 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

TonyRusin

Hi,

The DLookup function return a field value in a domain, or specified set of records.

it takes the following parameters.

The syntax of the DLookup() function is as follows:

   DLookup(Expression, Domain [, Criteria])
The criteria argument is an optional string expression that you can use 
to restrict the range of the data that the DLookup() function is performed on.
Note that the criteria argument is identical to the WHERE clause in an SQL 
expression (except that you do not use the keyword WHERE).
You can Specify a Numeric Criteria, Numeric Criteria that Comes 
from a Field on a Form and Textual Criteria.
Please refer to the link below for additional information and trouble shooting
http://support.microsoft.com/?kbid=208786#XSLTH3120121123120121120120
For further information on the criteria that can be used please refer below:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/html/achowSpecifyTextCriteriaControlForm_HV05188171.asp
techie1111
reply 2

You can use google to search for other answers

 

More Articles

• UTC Dates
• Standalone aplication
• Setting Password Char in InputBox?
• Get Excel Sheet Names
• Autosave using VBA after n minutes
• Why Excel 2003 keeps PivotItems with zero record count after refr...
• vba error message
• Collections of control - evaluating the name of a control that ha...
• Matrix syntax
• Link to Lotus Notes Document through Excel
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• macro script?
• 1004 Run-time error
• read line from table cell for vba in ms
• Generate XML from Excel Data
• Unable to create .NET class in VBA
• Needing extract elements XML to a listco
• VBA eBook
• Loosing Reference to Common Objects (i.s
• autocomplete
• Memory issue with variable declaration i
• SELECT syntax in VBA for retrieving info
• Using internal IP Address (Printers) in
• To dim or not to dim
• Path of MDB
• Collections Class For Each Next

Hot Articles

• How to copy pivot table RESULT from Acce
• Array lengths
• Writing To Text File Without Quotes
• Input from user form put into specified
• Does KeyPress event trap "Backspace
• passing commands to VBA in PPT?
• Control Break Trap will not work whilst
• Auto Initiate Excel Macro
• VBA Shell Function / Windows API Create
• Cannot close all instances of excel afte
• Another SendKeys
• reportbuilder
• Help with largest values and counts of t
• [Access SQL]: Have a function similar Or
• Stupid Question, how to turn Question Ma

Recommend Articles

• Referencing unregistered DLL
• Error refencing DLL in XLA
• Challenge writing a macro for setting Me
• need help with email attachement
• Wanting generate a HTML output right to
• Sort table based on array
• Dialogsheets vs Userforms
• XP style appearance
• VBA tapi caller ID
• Access 97 does not close after running c
• User Input on Range Selection
• how to read https://
• Access data source question
• Connecting to a split Database from Acce
• Open a Word Document