aidanie
asked on
SQL-INSERT statement
Hello...can anyone help me write this sql statement in VB?
INSERT INTO SECTOR[SECTOR ID]
VALUES(text1.text)
-------------------------- ------
TABLE NAME = SECTOR
FIELD NAME = SECTOR ID
VALUE = GET FROM TEXT3
INSERT INTO SECTOR[SECTOR ID]
VALUES(text1.text)
--------------------------
TABLE NAME = SECTOR
FIELD NAME = SECTOR ID
VALUE = GET FROM TEXT3
Arthur_Wood, shouldn't the field name be in () rather than [] bracket? i'm not sure abt that but i use () all along. Is [] also acceptable? and a string variable should be inside ''.
INSERT INTO SECTOR (SECTOR ID) VALUES('" & text1.text & "')
aidanie, ur values should get from text1 or text3?
INSERT INTO SECTOR (SECTOR ID) VALUES('" & text1.text & "')
aidanie, ur values should get from text1 or text3?
ASKER
andyleece,
value get from text1...
i try this code...but the value is not inserted into the table..
value get from text1...
i try this code...but the value is not inserted into the table..
Arthur_Wood, shouldn't the field name be in () rather than [] bracket? i'm not sure abt that but i use () all along. Is [] also acceptable? and a string variable should be inside ''.
INSERT INTO SECTOR (SECTOR ID) VALUES('" & text1.text & "')
aidanie, ur values should get from text1 or text3?
INSERT INTO SECTOR (SECTOR ID) VALUES('" & text1.text & "')
aidanie, ur values should get from text1 or text3?
sorry, refresh made my comment being post again, ignore it.
anyway, did u execute the query?
SQL = INSERT INTO SECTOR (SECTOR ID) VALUES('" & text1.text & "')
db.execute(SQL)
anyway, did u execute the query?
SQL = INSERT INTO SECTOR (SECTOR ID) VALUES('" & text1.text & "')
db.execute(SQL)
Since the column name "SECTOR ID" has a space in it it needs to be in square brackets, as follows:
"INSERT INTO SECTOR ([SECTOR ID]) VALUES('" & text1.text & "')"
Anthony
"INSERT INTO SECTOR ([SECTOR ID]) VALUES('" & text1.text & "')"
Anthony
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
And Then, Use This Function:
Public Function sqlValue(ParamArray F() As Variant) As String
Dim t As String, i As Byte
Dim s As String
t = ""
For i = 0 To UBound(F)
t = t & "'" & Replace(F(i), "'", "''") & "'"
't = t & "'" & f(i) & "'"
If i <> UBound(F) Then
t = t + ","
End If
Next i
sqlValue = t
End Function
Public Function sqlValue(ParamArray F() As Variant) As String
Dim t As String, i As Byte
Dim s As String
t = ""
For i = 0 To UBound(F)
t = t & "'" & Replace(F(i), "'", "''") & "'"
't = t & "'" & f(i) & "'"
If i <> UBound(F) Then
t = t + ","
End If
Next i
sqlValue = t
End Function
Divvy,
I suspect you hit the answer button by mistake. If not please refrain from doing so, you have been here long enough to know better.
Thanks,
Anthony
I suspect you hit the answer button by mistake. If not please refrain from doing so, you have been here long enough to know better.
Thanks,
Anthony
aidanie, try acperkins's comment, put the field name inside [] bracket.
sorry, but yes, the [Sector ID] shoult also be encosed in (...). The [...] are REQUIRED because of the embedded blank in the name of the field...Access DOES NOT LIKE BLANKS in field names, when used elsewhere (such as in SQL statements.
so the line should have read:
INSERT INTO SECTOR ([SECTOR ID]) VALUES('" & text1.text & "')
so the line should have read:
INSERT INTO SECTOR ([SECTOR ID]) VALUES('" & text1.text & "')
"INSERT INTO SECTOR[SECTOR ID] VALUES(" & text1.text & ")"
as a string variable
Post the Code that you are trying to use.