sql update text and numbers

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi everybody,
I'm working on an Access Project and I need to update a table (Companies)
with the following info

MainContact = Me.FName + Me. LName
Contact_ID = Me.Contact_ID

Is adding the L.Name but I'm having a hard time combining the rest...

strSql = "Update Companies Set MainContact = '" & Me.LName & _
"' Where Companies.Company_ID = " & Me.Company_ID
CurrentProject.Connection.Execute strSql, dbFailOnError

Thanks for any help!
 
What do you mean by 'combining the rest'? You also show MainContact as being
set to Me.FName & Me.LName (presume you want a space in there also), but in
your update SQL, you only show it being set to Me.LName.

What happens to Contact_ID?
 
Chaim,
I know it is so simple you don't see where I'm having the problem ;)
I'm trying to set the value to Main Contact (working ok)
AND
Contact_ID = Me.Contact_ID

Somehow I'm making a mistake somewhere...

strSql = "Update Companies Set MainContact = '" & Me.FName & " " & Me.LName
& _
"' Where Companies.Company_ID = " & Me.Company_ID
CurrentProject.Connection.Execute strSql, dbFailOnError
 
Better now. The SQL will look as follows:
strSql = "Update Companies " & _
"Set MainContact = '" & Me.FName & " " & Me.LName & ", " & _
"Contact_ID = " & Me.Contact_ID" & _
"' Where Companies.Company_ID = " & Me.Company_ID
CurrentProject.Connection.Execute strSql, dbFailOnError

Just comma-separate the fields being updated.

Good Luck!
 
Thanks again Chaim,
The only thing is that the Contact ID is a different field, now is copying
all the information to the field MainContact. I was looking to update the
FName and LName to the MainContact AND The Contact_ID to Contact_ID
 
I just noticed that my last post here had ---> Me.Contact_ID"

That trailing quote shouldn't be there.

I also messed up the separator. ", " should be "', ". The single quote is
needed to close the MainContact field value.

Sorry about that.
 
Back
Top