When I write code inside textbox doesn't accept it

问题: I have a textbox in a form. I use this textbox to write "Codes" and then I save it in the table in the database through the SQL insert statement, but the code doesn't accep...

问题:

I have a textbox in a form. I use this textbox to write "Codes" and then I save it in the table in the database through the SQL insert statement, but the code doesn't accept to run and gives me an error message: Run-Time error '3075'.

type of database: Access database type of field data: LongText

What the problem and how to pass all same problems when I need to save codes inside the database field.

When I try to save the code without (') it's working!

I use this SQL Statement:

CurrentDb.Execute "Update Tbl_Codes Set [LP_ID]= " & Me.txtID & ", 
[Code_Title]='" & Me.txtTitle & "'" _
& " ,[Code_Des]= '" & Me.txtDes & "',[Code_Key]= '" & Me.txtKey & "', 
[Notes]= '" & Me.txtNotes & "'" _
& " Where [ID]= " & Me.txtID1 & ""

And I want to save this Code:

DSum("Field1";"Table";"Field2=  '" & Value & "'")

回答1:

Please change your code as follows. You need to escape single quotes by doubling them up. A simple replace will work for your.

CurrentDb.Execute "Update Tbl_Codes Set [LP_ID]= " & Replace(Me.txtID,"'","''") & ", 
[Code_Title]='" & Replace(Me.txtTitle,"'","''") & "'" _
& " ,[Code_Des]= '" & Replace(Me.txtDes,"'","''") & "',[Code_Key]= '" & Replace(Me.txtKey,"'","''") & "', 
[Notes]= '" & Replace(Me.txtNotes,"'","''") & "'" _
& " Where [ID]= " & Me.txtID1 & ""
DSum("Field1";"Table";"Field2=  '" & Replace(Value,"'","''") & "'")
  • 发表于 2019-02-14 18:19
  • 阅读 ( 203 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除