balfoura
10-03-2008, 06:16 AM
I am hoping someone can help me with a problem I've been having. I am trying to make a concatenation function to use in a query. This is my first big access project and I'm really not the best at coding.
The code I have so far started with someone else's concatenation function which I tried to adapt to my needs. A few notes:
ID1 and ID2 are numeric ID numbers and are not strings.
If I take out the where clause, the rest of the function works just fine. I just don't get the results I want of course.
I've checked and rechecked the parameters in the query to make sure there aren't any misspellings.
I'm very new to this and might very well have made a huge mistake somewhere.
As the code is now, I'm getting a data type mismatch which I think is because the ID values aren't strings. However, I don't know the correct syntax and I haven't been able to find a syntax that will work in my trips around the net. As I try to fix my code I've been going between the errors 'data type mismatch in criteria expression' and 'too few parameters.'
Here is the beginning of my function:
Public Function Concat(ID1, ID2, ConField, Match1, Match2) As Variant
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim SQL As String
Dim vConc As Variant
Set db = CurrentDb
vConc = ""
SQL = "SELECT " & ConField & " As Conc" & _
" FROM tblPhysCreds INNER JOIN tblCreds" & _
" ON " & Match1 & " = " & Match2 & "" & _
" WHERE " & ID1 & " = '" & ID2 & "'"
Set rs = db.OpenRecordset(SQL)
So I'm pretty sure the issue is with the syntax of the where clause and maybe the way I handle my parameters. Any help or advice would be appreciated and I'll gladly answer any questions about my database structure.
The code I have so far started with someone else's concatenation function which I tried to adapt to my needs. A few notes:
ID1 and ID2 are numeric ID numbers and are not strings.
If I take out the where clause, the rest of the function works just fine. I just don't get the results I want of course.
I've checked and rechecked the parameters in the query to make sure there aren't any misspellings.
I'm very new to this and might very well have made a huge mistake somewhere.
As the code is now, I'm getting a data type mismatch which I think is because the ID values aren't strings. However, I don't know the correct syntax and I haven't been able to find a syntax that will work in my trips around the net. As I try to fix my code I've been going between the errors 'data type mismatch in criteria expression' and 'too few parameters.'
Here is the beginning of my function:
Public Function Concat(ID1, ID2, ConField, Match1, Match2) As Variant
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim SQL As String
Dim vConc As Variant
Set db = CurrentDb
vConc = ""
SQL = "SELECT " & ConField & " As Conc" & _
" FROM tblPhysCreds INNER JOIN tblCreds" & _
" ON " & Match1 & " = " & Match2 & "" & _
" WHERE " & ID1 & " = '" & ID2 & "'"
Set rs = db.OpenRecordset(SQL)
So I'm pretty sure the issue is with the syntax of the where clause and maybe the way I handle my parameters. Any help or advice would be appreciated and I'll gladly answer any questions about my database structure.