I am converting an Access app to a web app, and I am having trouble converting this vb/SQL into views. It doesn't seem like that hard problem, but it is really throwing me for a loop.
Public Function GetProjectNumber(ByVal HeaderID As Long) As String
Dim retval As String
Dim rst As New ADODB.Recordset
Dim tempID As Long
On Error GoTo Err_Handler
rst.Open "SELECT TransferID, ProjectID FROM dbo.tblProject WHERE HeaderID = " & HeaderID
If Not (rst.EOF And rst.BOF) Then
If IsNull(rst!TransferID) Then
retval = rst!ProjectID
Else
tempID = rst!TransferID
If rst.State = adStateOpen Then rst.Close
rst.Open "SELECT ProjectID FROM dbo.tblProject WHERE HeaderID = " & tempID
If rst.EOF And rst.BOF Then
retval = "Transfer from ????"
Else
retval = "Transfer from " & rst!ProjectID
End If
End If
End If
If rst.State = adStateOpen Then rst.Close
Exit_Handler:
Set rst = Nothing
GetProjectNumber = retval
Exit Function
End Function
I tried using a nested case statement, but cases can't be applied to each row returned. Is there a way to do this with IIF? Or to make this a function?