G
Guest
I have through two sepate questions got some answers which have helped with
my problem
i have a table sellers and need to assign a seller codde to each made up of
parts of surname and forname and two digits.
the code below works so long as they are not O'Brien or O'Donnell or othe O'
surnames
Public Sub MakeRef()
Dim strWhere As String
Dim ingnextnum As Long
Dim s_name2 As String
Dim F_name2 As String
If Len(Nz(Me!F_Name, "")) < 2 Then
'blank first name.... don't do anything
Exit Sub
End If
If Len(Nz(Me!S_Name, "")) < 2 Then
'blank surname....don't do anything
Exit Sub
End If
s_name2 = Left(Me!S_Name, 2)
F_name2 = Left(me!F_name, 2)
strWhere = "(S_name like '" & s_name2 & "*')" & _
" and (F_name like '" & F_name2 & "*')"
If IsNull(Me!ID) = False Then
' this not a new reocrd, so we must exclude this reocrd
strWhere = strWhere & " and (id <> " & Me!ID & ")"
End If
lngNextNum = DCount("*", "clients", strWhere) + 1
Me.C_ref = s_name2 & F_name2 & Format(lngNextNum, "00")
End Sub
but if surname is O' gives error code
run time error 3075
Synatx error(missing operator) in query expression '(S_Name like'O''*') and
(F_Name like 'je*') and (id<>2)'
I tried putting in the following code
if mid(S_Name,2,1)="'" then s_name2 =mid(S_Name,1,1)&mid(S_Name,3,1)
else
s_name2=left(me!sname,2)
this gets round the apostrophe but won't let two sellers with the same
initials eg conor o'Brien and Colm O'Brien as it doesn't increment the 01
part of key.
where am i going wrong
colm
my problem
i have a table sellers and need to assign a seller codde to each made up of
parts of surname and forname and two digits.
the code below works so long as they are not O'Brien or O'Donnell or othe O'
surnames
Public Sub MakeRef()
Dim strWhere As String
Dim ingnextnum As Long
Dim s_name2 As String
Dim F_name2 As String
If Len(Nz(Me!F_Name, "")) < 2 Then
'blank first name.... don't do anything
Exit Sub
End If
If Len(Nz(Me!S_Name, "")) < 2 Then
'blank surname....don't do anything
Exit Sub
End If
s_name2 = Left(Me!S_Name, 2)
F_name2 = Left(me!F_name, 2)
strWhere = "(S_name like '" & s_name2 & "*')" & _
" and (F_name like '" & F_name2 & "*')"
If IsNull(Me!ID) = False Then
' this not a new reocrd, so we must exclude this reocrd
strWhere = strWhere & " and (id <> " & Me!ID & ")"
End If
lngNextNum = DCount("*", "clients", strWhere) + 1
Me.C_ref = s_name2 & F_name2 & Format(lngNextNum, "00")
End Sub
but if surname is O' gives error code
run time error 3075
Synatx error(missing operator) in query expression '(S_Name like'O''*') and
(F_Name like 'je*') and (id<>2)'
I tried putting in the following code
if mid(S_Name,2,1)="'" then s_name2 =mid(S_Name,1,1)&mid(S_Name,3,1)
else
s_name2=left(me!sname,2)
this gets round the apostrophe but won't let two sellers with the same
initials eg conor o'Brien and Colm O'Brien as it doesn't increment the 01
part of key.
where am i going wrong
colm