Error 2465; Can't Find Field

K

KSmith

The section of code below is causing me problems.

Private Sub AddBadParts()

Dim dbs As DAO.Database
Dim strSQL As String
Dim MyDate
Dim MyTime

Set dbs = CurrentDb

'strSQL = "INSERT INTO tblTally ([CatalogNumber]) VALUES (" &
Me.[txtCatNum] & ");"
strSQL = "INSERT INTO tblTally ([CatalogNumber]) VALUES (""Hello
101st Try"");"

dbs.Execute strSQL

End Sub

ID - is the first field in the table (auto number)
CatalogNumber - is the second field in the table (text)

txtCatNum is a TextBox on the form that displays the data.

The strSQL line above that I have " ' " commented out is the line that gives
me the Error 2465 Can't find the field "|" in my expression.

The strSQL line below that one works. It puts the " Hello" statement in the
CatalogNumber Field.

Thanks in advance for all of your help.
 
K

KSmith

I'm still having trouble with this form. The form that I copied from works
great.
It's like I get one thing to working and something else screws up. Is there
an in-correct way to copy a form?

Here is what I done to get where I am today.

I clicked on 'without opening' the 1st form.
Pressed 'Ctrl C'
Pressed 'Ctrl V'
And re-named the form in the dialog box.

Changed the Record Source Line of the 2nd form.
Renamed the text boxes of the ones that changed, some stayed the same.
Most of the text boxes are bound to a field in the two main tables.

This is crazy. I don't understand why it works in one form but not in
another.

Is there a 'special way' that I need to be calling a text box from the form?

Thanks for the help.
--
KSmith


Marshall Barton said:
KSmith said:
The section of code below is causing me problems.

Private Sub AddBadParts()

Dim dbs As DAO.Database
Dim strSQL As String
Dim MyDate
Dim MyTime

Set dbs = CurrentDb

'strSQL = "INSERT INTO tblTally ([CatalogNumber]) VALUES (" &
Me.[txtCatNum] & ");"
strSQL = "INSERT INTO tblTally ([CatalogNumber]) VALUES (""Hello
101st Try"");"

dbs.Execute strSQL

End Sub

ID - is the first field in the table (auto number)
CatalogNumber - is the second field in the table (text)

txtCatNum is a TextBox on the form that displays the data.

The strSQL line above that I have " ' " commented out is the line that gives
me the Error 2465 Can't find the field "|" in my expression.

The strSQL line below that one works. It puts the " Hello" statement in the
CatalogNumber Field.

Because CatalogNumber is a text field, you must put the
value in quotes:

strSQL = "INSERT INTO tblTally ([CatalogNumber]) VALUES ("""
& Me.[txtCatNum] & """)"

Are you sure txtCatNum actually has something in it when the
code runs?
 
K

KSmith

Man you may have 'Made My Day'; I'm not using a query! I am trying to do
this by using the tables. Does this make a difference?

My only experence prior to this was command line dBaseIV programming, and I
didn't use queries.

If you use a query and update a field via a form, does it update the table
without any additional programming?

I have played around making queries and know how to do it, but really didn't
see the need. Before (in dBaseIV) I just find the correct record and
replaced the field in question with whatever needed to be their.

And again, Thanks a lot for your help.
 
K

KSmith

Thanks for all of you help and patience.
I took a closer look at the form that is working and compared it to the one
that wasn’t.

I made some errors.

On the form that works I refer to the control names in the code. In the one
that wasn’t working I did a combination of both. I was calling the control
name in some places and the field name in others by using “FieldName_tblNameâ€
or “tblName.FieldName†.

I think it was confusing to Access, I know I was!

Again, Thank you for your time and patience.
 
K

KSmith

The crazy thing about this is the last thing you mentioned. The original
form works great! Briefly what the original form does is display info from
two tables. The text boxes that displays this are bound to the two main
tables. There are two other unbound text boxes that the user will enter data
into. There’s a section of code that takes the unbound text box data, does a
calculation, and uses this calculation to subtract the calculated amount from
a field in the ‘top’ table and add this amount to a field in the ‘bottom’
table.

There is a section of code that appends some of the bound and unbound text
box data to another table for tracking purposes.

The original works and the copy doesn’t.

There must be something that I don’t have set correctly.

Anyway thanks for the help. If I figure it out I will post what I find.
 

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