Run Time 2465

Gavx

Registered User.
Local time
Today, 14:18
Joined
Mar 8, 2014
Messages
155
I am receiving this error when trying to run this code.
Can someone tell me what I am doing wrong please.



Private Sub txtGuestName_AfterUpdate()
'Format first name to Proper and ignore formatting on last name
Dim fName As String, lName As String

fName = StrConv(Left([Me.txtGuestName], InStr(1, [Me.txtGuestName], " ") - 1), vbProperCase)

lName = Right(Trim([txtGuestName]), Len(Trim([txtGuestName])) - InStr(1, [txtGuestName], " "))

Me.txtGuestName = fName & " " & lName


Me.Parent.subBookingProduct.Requery
Me.Parent.subBookingProductDetail.Requery
Me.Parent.subBookingProduct!cbGuestID.Requery

End Sub
 
I am receiving this error when trying to run this code.
Can someone tell me what I am doing wrong please.



Private Sub txtGuestName_AfterUpdate()
'Format first name to Proper and ignore formatting on last name
Dim fName As String, lName As String

fName = StrConv(Left([Me.txtGuestName], InStr(1, [Me.txtGuestName], " ") - 1), vbProperCase)

lName = Right(Trim([txtGuestName]), Len(Trim([txtGuestName])) - InStr(1, [txtGuestName], " "))

Me.txtGuestName = fName & " " & lName


Me.Parent.subBookingProduct.Requery
Me.Parent.subBookingProductDetail.Requery
Me.Parent.subBookingProduct!cbGuestID.Requery

End Sub

Try this:

Code:
fName = StrConv(Left(Me.txtGuestName, InStr(1, Me.txtGuestName, " ") - 1), vbProperCase)

Simply remove the square brackets. I only checked that line and no error returned and function worked. The square brackets were encompassing the "Me." part which were causing the problem.
 
Last edited:
What is the error message?
And in which code line do you get the error?

It could be the use of "[]"
Code:
..
    fName = StrConv(Left([B][COLOR=Red][[/COLOR][/B]Me.txtGuestName[B][COLOR=Red]][/COLOR][/B], InStr(1,[B][COLOR=Red] [[/COLOR][/B]Me.txtGuestName[B][COLOR=Red]][/COLOR][/B], " ") - 1), vbProperCase)
    lName = Right(Trim([B][COLOR=Red][[/COLOR][/B]txtGuestName[B][COLOR=Red]][/COLOR][/B]), Len(Trim([B][COLOR=Red][[/COLOR][/B]txtGuestName[B][COLOR=Red]][/COLOR][/B])) - InStr(1, [COLOR=Red][[/COLOR]txtGuestName[COLOR=Red]][/COLOR], " "))
Try the below instead:
Code:
Private Sub txtGuestName_AfterUpdate()
  'Format first name to Proper and ignore formatting on last name
  Dim fName As String, lName As String
  
  fName = StrConv(Left(Me.txtGuestName, InStr(1, Me.txtGuestName, " ") - 1), vbProperCase)
  
  lName = Right(Trim(Me.txtGuestName), Len(Trim(Me.txtGuestName)) - InStr(1, Me.txtGuestName, " "))
  
  Me.txtGuestName = fName & " " & lName
  
  
  Me.Parent.subBookingProduct.Requery
  Me.Parent.subBookingProductDetail.Requery
  Me.Parent.subBookingProduct!cbGuestID.Requery

End Sub
Then you need to be more consequent in your programming style, in some places you use Me in front in other not!
 
Your a legend and thanks for the tip.
 
if your fields have spaces then you need the square brackets. The me is generally not required, but I expect you would need this sort of syntax. (where brackets ARE required, eg in SQL update strings)

[me].[field name]

and not

[me.field name]
 

Users who are viewing this thread

Back
Top Bottom