It will help to determine exactly where your error is happening.  Put a breakpoint or stop statement in there (see below), and use F8 to step through the code. 
 
I would probably use Cstr() instead of Str().  You may be running into null values when you try to cast to string??  (Although now that I look at your SQL statement, probably not...).  You may want to employ NZ() inside the Cstr().
 
I suspect your recordset is opening OK, you'd be getting a SQL-specific error otherwise.
 
Regardless, stepping through your code is necessary to determine where the problem lies. 
 

Tom Oakes
Personal PC Consultants, Inc.
[EMAIL PROTECTED]
503.230.0911 (O)
402.968.6946 (C)
734.264.0911 (F)




From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Mylz Kitufu
Sent: Friday, December 02, 2005 5:22 AM
To: [email protected]
Subject: [AccessDevelopers] Type Mismatch error

When I run the code below, I get the TYPE MISMATCH ERROR when I run

?NextJournalNumber In the immediate window.

It doesn't matter whether I use nextjournalnumber() as string.

What Am I doing wrong? Am running Access 2000 adp / mssql7.

Godfrey

CODE Follows------------------------------------------------------->

Function NextJournalNumber()

Dim sql, srec As String
Dim rst As New ADODB.Recordset
 
Stop
 
srec = "00000"
sql = "select cast(strmrefno as money) as SrefNo from gl_trans_hdr where
t_VCHRtype='I' and len(strmrefno)=5 order by cast(strmrefno as money)desc"
rst.Open sql, CurrentProject.Connection, adOpenStatic, adLockReadOnly
If rst.RecordCount > 0 Then
    rst.MoveFirst
    If rst!SrefNo > Val(srec) Then
       srec = str(rst!SrefNo)
    End If
End If
rst.Close

NextJournalNumber = Right("00000" + Trim(str(Val(srec) + 1)), 5)

End Function


---------------------------------------------------------------------------------->
In the end, we will remember not the words of our enemies,
but the silence of our friends - Martin Luther King Jr.
---------------------------------------------------------------------------------->


     
     
           
___________________________________________________________
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com



Please zip all files prior to uploading to Files section.




SPONSORED LINKS
Microsoft access developer Microsoft access help Microsoft access database
Microsoft access training Microsoft access training course Microsoft access programming


YAHOO! GROUPS LINKS




Reply via email to