Graham,
Left(), Mid(), and Right() are functions that read a substring form a
string. Since they are 'read' functions, this won't work (as you found out):
Mid([Customers], 1, 1) = "Y"
Instead of using the Mid() function, you could use:
1st position:
Customers = "Y" & Right(Customers, 9)
10th position:
Customers = "Y" & Left(Customers, 9)
2nd - 9th positions:
Customers = Left(Customers, Pos - 1) & "Y" & Right(Customers, 10 - Pos)
Another way to change the permissions string would be to use a function like
(UNTESTED AIR CODE!!)
' State = Y or N
' Pos = the char in the string to change (ie 2nd Char or 8th Char)
Public Function SetPermissions(State As String, Pos As Integer) As String
Dim tmp As String
Select Case Pos
Case 1 'change the first char
tmp = State & Right(Customers, 9)
Case 10 'change the last char
tmp = State & Left(Customers, 9)
Case 2 - 9 'all other chars
tmp = Left(Customers, Pos - 1) & State & Right(Customers, 10 -
Pos)
Else 'if Pos out of range
' add better err handling than this
MsgBox "ERROR"
End Select
'return the value
SetPermissions = tmp
End Function
You would call the function like this:
' 1 = 1st char
If Cust01 = True Then
Customers = SetPermissions("Y", 1)
Else
Customers = SetPermissions("N", 1)
End If
'or
' 8 = 8th char
If Cust01 = True Then
Customers = SetPermissions("Y", 8)
Else
Customers = SetPermissions("N", 8)
End If
HTH
Steve
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)
Graham said:
Thanks Jeff,
Customer is a string of 10 char each char is "Y" OR "N"
It is to allow aceess permissions to the customer program
1st char Y = View N = No View
2nd Char Y = Amend N = No Amend
3rd Char Y = Add New Record N = Can't add
4th Char Y = Delete Record N = Can't Delete
and so on
When updating it a check box (Cust01) is used and I was
just trying to put the string back to show an update.
Hope you can understand this
Thanks
-----Original Message-----
Graham
From the expression you provided, it seems like you are trying to modify
something (?a field) named [Customer] by replacing the first character with
either a "Y" or a "N".
If you already have a value for "Cust01" (whatever that might be), why do
you need to modify [Customer]?
We aren't there ... can you provide a bit more description of WHAT you are
trying to accomplish? Help us see the big picture. You've described a very
narrow, tightly-defined "HOW".
--
More info, please ...
Jeff Boyce
<Access MVP>
.