type mismatch

  • Thread starter BenEl via AccessMonster.com
  • Start date
B

BenEl via AccessMonster.com

Hi. I have a form (parent table) with an unbound text box. When the user hits
the "close" button, whatever is written in the text box is put into the child
table. I am getting a type mismatch error and can't figure out what's wrong!
Can someone have a look at my code?

If EnterCommentText.Value <> "" Then

LInsert = "INSERT INTO [tblCommentsHistory] ([Auto Number],
[EnterComments], [UpdateWho])"
LInsert = LInsert & " VALUES (" & [Task Number] & ", " & Replace
(EnterCommentText.Value, "'", """) & ", " & LoggedUser & ")

db.Execute LInsert, dbFailOnError

Form_frmModifyTask.Refresh

EnterCommentText.Value = ""

DoCmd.Close acForm, "frmModifyTask"
Else
DoCmd.Close acForm, "frmModifyTask"
End If


Thanks!
 
J

John Spencer

Missing text delimiters
Closing ")" is outside quote marks

LInsert = "INSERT INTO [tblCommentsHistory] " & _
"([Auto Number], [EnterComments], [UpdateWho])" & VBCRLF
LInsert = LInsert & " VALUES (" & [Task Number] & ", '" & _
Replace(EnterCommentText.Value, "'", "''") & "', '" & LoggedUser & "' )"

'For trouble shooting add the following line
Debug.Print "LInsert is: " & vbcrlf & LInsert

Now you can check and see if that looks like a well formed SQL statement.

I am guessing that EnterComments is a text or memo field and LoggedUser is a
text field.


John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
 
B

BenEl via AccessMonster.com

Fabulous! Thanks!

John said:
Missing text delimiters
Closing ")" is outside quote marks

LInsert = "INSERT INTO [tblCommentsHistory] " & _
"([Auto Number], [EnterComments], [UpdateWho])" & VBCRLF
LInsert = LInsert & " VALUES (" & [Task Number] & ", '" & _
Replace(EnterCommentText.Value, "'", "''") & "', '" & LoggedUser & "' )"

'For trouble shooting add the following line
Debug.Print "LInsert is: " & vbcrlf & LInsert

Now you can check and see if that looks like a well formed SQL statement.

I am guessing that EnterComments is a text or memo field and LoggedUser is a
text field.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
Hi. I have a form (parent table) with an unbound text box. When the user hits
the "close" button, whatever is written in the text box is put into the child
[quoted text clipped - 20 lines]
 

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