OK this is my last try. If you still can't get it to work, you need tosend
the files.
Tim
'*******************************
Function GetUnitCost(ProdCode)
Const DB_NAME As String = "qcpProg.mdb"
Const DB_PW As String = "myPasswordx"
Dim retVal As String
Dim conn As Object
Dim rst As Object
Dim sql As String
Dim dbPath As String
On Error GoTo haveError
dbPath = Left(ThisWorkbook.Path, _
InStrRev(ThisWorkbook.Path, "\")) & _
DB_NAME
retVal = "NoProdCodeSupplied"
If Len(ProdCode) > 0 Then
sql = "select UnitCost from tProduct where " & _
" ProductCode = '" & ProdCode & "'"
Set conn = CreateObject("ADODB.Connection")
' conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
' "Data Source=" & dbPath & _
' ";Jet OLEDB
atabase Password="& DB_PW & ";"
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
dbPath & ";Jet OLEDB:System Database=qcpSystem.mdw;" & _
"User ID=michele;Password=" & DB_PW & ";"
Set rst = conn.Execute(sql)
If Not rst.EOF Then
retVal = rst.Fields(0).Value
Else
retVal = "UnknownProdCode!"
End If
rst.Close
conn.Close
End If
GetUnitCost = retVal
Exit Function
haveError:
GetUnitCost = Err.Description
End Function
Wow, this is frustrating. I tried some of the options on Tim's link,
but I'm not skilled enough to understand what to do. There is a user
(michele) and a workgroup system file (qcpSystem.mdw in the same
folder as the access database). Can anyone help with the updated code
to add this information?
I had a third friend look at it (an Access programmer) and she didn't
know what the problem was either.
Is Option Explicit supposed to be at the top of the module?
I tried copying the code into a blank spreadsheet. Same thing. Sign..
Thanks again everyone and anyone who can help,
Michele