RichardMarbat
New member
- Local time
- Today, 16:29
- Joined
- Dec 30, 2021
- Messages
- 8
Hello
can someone help me with this ... I'm new to access, not programming, please see the code below (i know it's full of rubbish etc, I'm just testing the framework...)
JoinName is the function I'm working on, test is just to fire it, eventually, I want to pass fields from a table and base the return on the parameters passed
the below seems to work fine... BUT when I use this as a query
all I'm doing is passing 2 fields and having them returned as one string (i want to do some logic on the values passed to determine the return value)
again the above works fine until one of the field values is empty then I get the message (x fields didn't update due to type conversion)
I just can't work it out, when I use the test function I can pass "" no problem, I tried to debug it and it would seem that access doesn't even pass the record to the function (I removed the first records field and the debug started at record 2) I added the IIF statement to try to pass a string where the value is empty, that didn't work... all my fields are strings, so I figure there is a difference between an empty string and an empty table field
any help would be greatly appreciated
thanks, Richard
Code Tags Added by UG
Please use Code Tags when posting VBA Code
Please read this for further information:-
https://www.access-programmers.co.u...e-use-code-tags-when-posting-vba-code.240420/
Please feel free to Remove this Comment
By the way I think your code was very well presented even before I added the code tags, but now look at it, it looks awesome!
can someone help me with this ... I'm new to access, not programming, please see the code below (i know it's full of rubbish etc, I'm just testing the framework...)
JoinName is the function I'm working on, test is just to fire it, eventually, I want to pass fields from a table and base the return on the parameters passed
the below seems to work fine... BUT when I use this as a query
Code:
UPDATE [Welcome-20211224] SET [Welcome-20211224].Fullname = joinname(IIf(IsEmpty([Welcome-20211224]![firstName])," ",[Welcome-20211224]![FirstName]),IIf(IsEmpty([Welcome-20211224]![lastname])," ",[Welcome-20211224]![lastname]));
all I'm doing is passing 2 fields and having them returned as one string (i want to do some logic on the values passed to determine the return value)
again the above works fine until one of the field values is empty then I get the message (x fields didn't update due to type conversion)
I just can't work it out, when I use the test function I can pass "" no problem, I tried to debug it and it would seem that access doesn't even pass the record to the function (I removed the first records field and the debug started at record 2) I added the IIF statement to try to pass a string where the value is empty, that didn't work... all my fields are strings, so I figure there is a difference between an empty string and an empty table field
any help would be greatly appreciated
thanks, Richard
Code:
---------------------------------------------------------------------------------------------------------------------------
Function joinname(aa1 As String, bb2 As String) As String
' joinname = Trim(name1) & " " & Trim(name2)
Debug.Print VarType(aa1)
Debug.Print VarType(bb2)
aa1 = Trim(Nz(aa1))
bb2 = Trim(Nz(bb2))
If aa1 = "" Or bb2 = "" Then
joinname = ""
Else
joinname = Trim(StrConv(aa1, vbProperCase)) & " " & Trim(StrConv(bb2, vbProperCase))
End If
End Function
---------------------------------------------------------------------------------------------------------------------------
Sub test()
Dim no1 As String
Dim no2 As String
Dim ret As String
Dim aa As String
no1 = "a"
no2 = "b"
ret = joinname(no1, no2)
Debug.Print ret
End Sub
Please use Code Tags when posting VBA Code
Please read this for further information:-
https://www.access-programmers.co.u...e-use-code-tags-when-posting-vba-code.240420/
Please feel free to Remove this Comment
By the way I think your code was very well presented even before I added the code tags, but now look at it, it looks awesome!
Last edited by a moderator: