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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IsEmpty(TipoKort) #Error

Status
Not open for further replies.

matrixindicator

IS-IT--Management
Sep 6, 2007
418
BE
I convert a short description of a street to a long with a function eg. CL -> CALLE
However if there is not a short description he writes #Error, how just to place a emmpty string "" if there is no short description for the street ?

What do I need to adapt to my code ?

Code:
Public Function TIPODESC(TipoKort As String) As String

Dim dbs As DAO.Database
Dim rst As DAO.Recordset

Set dbs = CurrentDb

Set rst = dbs.OpenRecordset("SELECT STREETDESC FROM TblStreet WHERE StreetCode =""" & TipoKort & """", dbOpenDynaset)

If IsEmpty(TipoKort) Then
    TIPODESC = ""
Else
    TIPODESC = rst!STREETDESC
End If

End Function
 
Replace the lot with

DLookup("StreetDesc", "tblStreet", "StreetCode='" & TipoKort & "'")

And that will work

John
 
Code:
Public Function TIPODESC(TipoKort As String) As String

Dim dbs As DAO.Database
Dim rst As DAO.Recordset

Set dbs = CurrentDb

Set rst = dbs.OpenRecordset("SELECT STREETDESC FROM TblStreet WHERE StreetCode ='" & TipoKort & "'", dbOpenDynaset)

If rst.EOF AND rst.BOF Then 
   TIPODESC = ""
Else
   TIPODESC = rst.Fields(0)
End If
rst.close

End Function
Code:
DLookup("StreetDesc", "tblStreet", "StreetCode='" & TipoKort & "'") & ""
 
How are ya matrixindicator . . .

Try this:
Code:
[blue]Public Function TIPODESC(TipoKort As String) As String

   Dim dbs As DAO.Database, rst As DAO.Recordset, SQL As String
   
   Set dbs = CurrentDb
   SQL = "SELECT STREETDESC " & _
         "FROM TblStreet " & _
         "WHERE StreetCode ='" & TipoKort & "';"
   Set rst = dbs.OpenRecordset(SQL, dbOpenDynaset)
   
   If Not rst.BOF Then
      If Trim(TipoKort & "") <> "" Then TIPODESC = rst!STREETDESC
   End If
   
   Set rst = Nothing
   Set dbs = Nothing

End Function[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top