Field Names with Spaces

D

Dorci

Access 2003 - My brackets aren't working.

I have the following piece of code:

With Me.RecordsetClone
.AddNew
![MTNumber] = Me.[MTNumber]
!Address = Me.Address
![City] = Me.[City]
![Postal Code] = Me.[Postal Code]

It keeps failing every time it gets to a field with spaces in the name, in
this case "Postal Code". I've tried with and without brackets and it still
fails. Any ideas? Thanks in advance.

~Dorci
 
D

Dirk Goldgar

Dorci said:
Access 2003 - My brackets aren't working.

I have the following piece of code:

With Me.RecordsetClone
.AddNew
![MTNumber] = Me.[MTNumber]
!Address = Me.Address
![City] = Me.[City]
![Postal Code] = Me.[Postal Code]

It keeps failing every time it gets to a field with spaces in the name, in
this case "Postal Code". I've tried with and without brackets and it
still
fails. Any ideas? Thanks in advance.


The above syntax, with the bracketing, is correct for fields with spaces in
the name. Double-check the name of the field. Maybe the field you're
referring to as "Postal Code" is really named "PostalCode", or "PostCode",
or something like that, and it's only its .Caption property that has the
space.
 
D

Dorci

THANK YOU!!! You're a genius!

Dirk Goldgar said:
Dorci said:
Access 2003 - My brackets aren't working.

I have the following piece of code:

With Me.RecordsetClone
.AddNew
![MTNumber] = Me.[MTNumber]
!Address = Me.Address
![City] = Me.[City]
![Postal Code] = Me.[Postal Code]

It keeps failing every time it gets to a field with spaces in the name, in
this case "Postal Code". I've tried with and without brackets and it
still
fails. Any ideas? Thanks in advance.


The above syntax, with the bracketing, is correct for fields with spaces in
the name. Double-check the name of the field. Maybe the field you're
referring to as "Postal Code" is really named "PostalCode", or "PostCode",
or something like that, and it's only its .Caption property that has the
space.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

David H

Certain religious orders have proclaimed that spaces in object names are
nothing short evil and should be purged from this world at any and all costs.

(Getting off that soapbox...)

Spaces in object names tend to be a bad thing. While they are allowed, they
can cause problems such as PostalCode vs. Postal Code example given above. If
the norm is to use spaces and you don't for a particular field then you might
find yourself in the situation wherein you just have to remember that its
PostalCode not Postal Code which can lead to issues for others. But if you
don't use them to begin with then you don't run into that problem.

I built a database this past year, where I screwed up two field names with
how I named them (spaces weren't an issue) and didn't realize it until it was
far too late to go back and change them.

Dorci said:
THANK YOU!!! You're a genius!

Dirk Goldgar said:
Dorci said:
Access 2003 - My brackets aren't working.

I have the following piece of code:

With Me.RecordsetClone
.AddNew
![MTNumber] = Me.[MTNumber]
!Address = Me.Address
![City] = Me.[City]
![Postal Code] = Me.[Postal Code]

It keeps failing every time it gets to a field with spaces in the name, in
this case "Postal Code". I've tried with and without brackets and it
still
fails. Any ideas? Thanks in advance.


The above syntax, with the bracketing, is correct for fields with spaces in
the name. Double-check the name of the field. Maybe the field you're
referring to as "Postal Code" is really named "PostalCode", or "PostCode",
or something like that, and it's only its .Caption property that has the
space.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

Shipsmate via AccessMonster.com said:
I'm not 100% sure, but I think it's not allowed to add records to a
recordsetclone.


Yes, it is, so long as the source recordset is updatable.
 
D

Dorci

You're preaching to the choir; I totally agree. If fact, I was surprised at
myself to think that I had done that. But as Dirk pointed out, I really
hadn't. There are no spaces in any of the field names as I had originally
thought (you see, I'm updating a db that I created some time ago); it was
their captions I was referring to.

David H said:
Certain religious orders have proclaimed that spaces in object names are
nothing short evil and should be purged from this world at any and all costs.

(Getting off that soapbox...)

Spaces in object names tend to be a bad thing. While they are allowed, they
can cause problems such as PostalCode vs. Postal Code example given above. If
the norm is to use spaces and you don't for a particular field then you might
find yourself in the situation wherein you just have to remember that its
PostalCode not Postal Code which can lead to issues for others. But if you
don't use them to begin with then you don't run into that problem.

I built a database this past year, where I screwed up two field names with
how I named them (spaces weren't an issue) and didn't realize it until it was
far too late to go back and change them.

Dorci said:
THANK YOU!!! You're a genius!

Dirk Goldgar said:
Access 2003 - My brackets aren't working.

I have the following piece of code:

With Me.RecordsetClone
.AddNew
![MTNumber] = Me.[MTNumber]
!Address = Me.Address
![City] = Me.[City]
![Postal Code] = Me.[Postal Code]

It keeps failing every time it gets to a field with spaces in the name, in
this case "Postal Code". I've tried with and without brackets and it
still
fails. Any ideas? Thanks in advance.


The above syntax, with the bracketing, is correct for fields with spaces in
the name. Double-check the name of the field. Maybe the field you're
referring to as "Postal Code" is really named "PostalCode", or "PostCode",
or something like that, and it's only its .Caption property that has the
space.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top