Solved spaces in AddNew fields caising issues... (1 Viewer)

Cal Varchar

New member
Local time
Tomorrow, 00:16
Joined
Jan 24, 2024
Messages
28
Hola Muchachos y Muchachas!

As you can see it's pretty festive here with the slew of errors that are getting thrown from this one statement.

Any ideas why, ONLY WHEN I HAVE a SPACE in the field name, i get this error?

Gracias!

errorAddNew.png

addnew.png
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:16
Joined
May 7, 2009
Messages
19,245
you replace ' with double ':

Adorec("Company") = Replace$("Boby's Company", "'", "''")
 

Cal Varchar

New member
Local time
Tomorrow, 00:16
Joined
Jan 24, 2024
Messages
28
you replace ' with double ':

Adorec("Company") = Replace$("Boby's Company", "'", "''")
I'm probably misunderstanding; the issue is with the "Job Title" field.

If I used "Address", it goes right through. And I would suspect that if I used "JobTitle", it would go right through. "Company" updates no matter what I put in: "Teddy's Company", "Bubby's Company"...all of that kind of stuff gets added to the DB.

Anytime I have spaces in a field/column name, it does not work.

FYI, there are spaces in the majority of field names in the DB.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:16
Joined
May 7, 2009
Messages
19,245
ok, then use .Fields()
.Fields(0) refers to the first field in your query
.Fields(1) is your second field:

ADOrec.AddNew
ADOrec.Fields(0) = "Bobby's Company"
ADOrec.Fields(1)="1231x312x31"
ADOrec.Update
 

isladogs

MVP / VIP
Local time
Today, 22:16
Joined
Jan 14, 2017
Messages
18,233
Best practice is to avoid spaces in field and object names. If you must use spaces enclose in square brackets [Job Title] or replace spaces with underscores: Job_Title
 

Cal Varchar

New member
Local time
Tomorrow, 00:16
Joined
Jan 24, 2024
Messages
28
ok, then use .Fields()
.Fields(0) refers to the first field in your query
.Fields(1) is your second field:

ADOrec.AddNew
ADOrec.Fields(0) = "Bobby's Company"
ADOrec.Fields(1)="1231x312x31"
ADOrec.Update
I looked through the help and found that, but it yielded something about an improper accessor, from what I remember.
 

Cal Varchar

New member
Local time
Tomorrow, 00:16
Joined
Jan 24, 2024
Messages
28
Best practice is to avoid spaces in field and object names. If you must use spaces enclose in square brackets [Job Title] or replace spaces with underscores: Job_Title
Yeeh. Thanks. I haven't put a space in a field name in my life, it's not my creation and renaming the fields, and everything they relate to, is beyong the scope of my duties and willingness.
 

Cal Varchar

New member
Local time
Tomorrow, 00:16
Joined
Jan 24, 2024
Messages
28
ok, then use .Fields()
.Fields(0) refers to the first field in your query
.Fields(1) is your second field:

ADOrec.AddNew
ADOrec.Fields(0) = "Bobby's Company"
ADOrec.Fields(1)="1231x312x31"
ADOrec.Update
ordinalError.png
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:16
Joined
May 7, 2009
Messages
19,245
i think you need to Save it not Update it.

'ADOrec.Update <= this is wrong
Adorec.Save


'==============
ADOrec.AddNew
ADOrec.Fields("Company") = "Bobby's Company"
ADOrec.Fields("Job Title")="1231x312x31"
ADOrec.Save
 
Last edited:

Cal Varchar

New member
Local time
Tomorrow, 00:16
Joined
Jan 24, 2024
Messages
28
i think you need to Save it not Update it.

'ADOrec.Update <= this is wrong
Adorec.Save


'==============
ADOrec.AddNew
ADOrec.Fields("Company") = "Bobby's Company"
ADOrec.Fields("Job Title")="1231x312x31"
ADOrec.Save
I've done a few tens of trials. Made sure that my SQL statement was correct and it works for Save and Update.
AND
Works with AND without .Fields without ordinals.
Works with ADOrec("fieldname"), but not ADOrec("field name")
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:16
Joined
May 7, 2009
Messages
19,245
i just tested it on SQLServer Express with space on field name (Job Title) and it does not have any error.
the error you have is you are Adding and using Update at the end, when you should use Save.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:16
Joined
May 7, 2009
Messages
19,245
..then what does Save do on a New record?
i tested it on my SQLServer and it saves the record.
what else does it do on New Record (AddNew method)?
 

Cal Varchar

New member
Local time
Tomorrow, 00:16
Joined
Jan 24, 2024
Messages
28
Arnel already gave you the answer:
Code:
ADOrec.Fields("field name") = "Whatever"
I tried it. It didn't work. That's up there in post #10

Almost all of these work EXCEPT those with ordinals AND those that use ("field name") That's been my experience. Maybe it's SQL Server 2016.

But you can see my code down below, perhaps someone can try running my original code and see if it works on their system.

As I say, it works ANY TIME I have a field name without a space. I'm certain that with "JobTitle" it would work.

I just thought of this. I'll try it with "Job Title" first, followed by "Company", when I have time. Might be a couple of hours.


addnew.png
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:16
Joined
May 7, 2009
Messages
19,245
BECAUSE YOU ARE USING ADOrec.Update
use ADOrec.Save

can't you see, it is highlighting that line?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 22:16
Joined
Sep 12, 2006
Messages
15,658
You need [field name] when there is a space, I think. Some version of that, with square brackets
 

Cal Varchar

New member
Local time
Tomorrow, 00:16
Joined
Jan 24, 2024
Messages
28
BECAUSE YOU ARE USING ADOrec.Update
use ADOrec.Save

can't you see, it is highlighting that line?
I think I said that it doesn't work with save either. Yeah, not particularly clearly, but that's what I meant up in #10.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:16
Joined
May 7, 2009
Messages
19,245
i can't believe that is True? like i said, i did re-create your table.
see this video
 

Users who are viewing this thread

Top Bottom