7 Replies - 1206 Views - Last Post: 03 March 2012 - 04:50 PM Rate Topic: -----

#1 newbownerton  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 08-February 12

Including variable in SQL command

Posted 03 March 2012 - 03:53 PM

Hi everyone,

I shamefully look for an answer to my newbie question :)

I have created a form that should allow user to communicate with the database. The search criteria are filled withing Textbox. Then the string from the textbox is transferred into the SQL Command string. However, it is not included...

SQLStr = "SELECT * FROM tblMain WHERE ID = " & txtSearchBox.Text & "'"
MsgBox(SQLStr)


And only this part is stored in SQLStr variable = "SELECT * FROM tblMain WHERE ID = " - (pops up in msg box)

Any hints? ;/

Is This A Good Question/Topic? 0
  • +

Replies To: Including variable in SQL command

#2 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 838
  • Joined: 21-December 11

Re: Including variable in SQL command

Posted 03 March 2012 - 04:13 PM

you say whenever you pass textbox text to SQLStr string, this string never change?
Was This Post Helpful? 0
  • +
  • -

#3 newbownerton  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 08-February 12

Re: Including variable in SQL command

Posted 03 March 2012 - 04:20 PM

View Postsela007, on 03 March 2012 - 04:13 PM, said:

you say whenever you pass textbox text to SQLStr string, this string never change?


Variable SQLstr is then shown in MsgBox:

Posted Image

So you see where it ends, variable - no matter what string it contains - is not included.
Was This Post Helpful? 0
  • +
  • -

#4 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Including variable in SQL command

Posted 03 March 2012 - 04:24 PM

View Postnewbownerton, on 04 March 2012 - 09:20 AM, said:

View Postsela007, on 03 March 2012 - 04:13 PM, said:

you say whenever you pass textbox text to SQLStr string, this string never change?


Variable SQLstr is then shown in MsgBox:

Posted Image

So you see where it ends, variable - no matter what string it contains - is not included.

Why would you add a msgbox to a string variable? You could use an InputBox for data entry…
Was This Post Helpful? 0
  • +
  • -

#5 newbownerton  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 08-February 12

Re: Including variable in SQL command

Posted 03 March 2012 - 04:25 PM

View PostDimitriV, on 03 March 2012 - 04:24 PM, said:

View Postnewbownerton, on 04 March 2012 - 09:20 AM, said:

View Postsela007, on 03 March 2012 - 04:13 PM, said:

you say whenever you pass textbox text to SQLStr string, this string never change?


Variable SQLstr is then shown in MsgBox:

Posted Image

So you see where it ends, variable - no matter what string it contains - is not included.

Why would you add a msgbox to a string variable? You could use an InputBox for data entry…


LoL i just added it to see how does the string look like, IF finally it will work properly - txtSearchBox.text will be included I will delete this line of code xD
Was This Post Helpful? 0
  • +
  • -

#6 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 838
  • Joined: 21-December 11

Re: Including variable in SQL command

Posted 03 March 2012 - 04:28 PM

can you post the whole code so we can see how SQLStr is declared and from where is passed.
Was This Post Helpful? 1
  • +
  • -

#7 newbownerton  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 08-February 12

Re: Including variable in SQL command

Posted 03 March 2012 - 04:38 PM

View Postsela007, on 03 March 2012 - 04:28 PM, said:

can you post the whole code so we can see how SQLStr is declared and from where is passed.


SQLstri is declared in Module:

Public SQLStr As String

Was This Post Helpful? 0
  • +
  • -

#8 newbownerton  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 08-February 12

Re: Including variable in SQL command

Posted 03 March 2012 - 04:50 PM

View Postsela007, on 03 March 2012 - 04:28 PM, said:

can you post the whole code so we can see how SQLStr is declared and from where is passed.


OMG... FIXED.

It had nothing to do with the string itself.

Thanks for trying to help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1