Connecting Tech Pros Worldwide Forums | Help | Site Map

SQL in ACCESS and VB6

Newbie
 
Join Date: Nov 2006
Location: Dasmariņas, Cavite
Posts: 27
#1: Dec 12 '06
PLS.... Help!!!
--------------------------------------------------------------------------------

hi commnunity

i have problem with sql,
i have created a table in Access Named TABLE1 in TABLE1 i have EmployeeNumber, Section, Posotion;

i assigned EmployeeNumber as text1.text
Section as text2.text
Posotion as text3.text
i have buttons name ADDrecord,

here is my code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. Dim EmployeeNumber As String
  3. Dim Section As String
  4. Dim Postion As String
  5.  
  6. Dim strSQL As String
  7. Text1.Text = EmployeeNumber
  8. Text2.Text = Section 
  9. Text3.Text = Position
  10.  
  11. strSQL = "INSERT INTO TABLE1 (EmployeeNumber, Section, Position) " & _
  12. "VALUES('" & [EmployeeNumber] & "','" & [Section] & _
  13. "'," & [Position] & ")"
  14. Adodc1.RecordSource = strSQL
  15. Adodc1.Recordset.Save
  16. Adodc1.Refresh
  17.  
  18.  
  19.  
  20. End Sub
  21.  
  22.  
  23. Private Sub Form_Load()
  24. Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Maan\My Documents\db4.mdb;Persist Security Info=False"
  25. Adodc1.RecordSource = "SELECT * FROM Table1"
  26. End Sub

is this Correct? pls.. make an example for me...


thank you in advance

Julius

--------------------------------------------------------------------------------

msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,875
#2: Dec 12 '06

re: SQL in ACCESS and VB6


Try this ...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. Dim EmployeeNumber As String
  3. Dim Section As String
  4. Dim Postion As String
  5. Dim strSQL As String
  6.  
  7. ' Wrong way around Julius, should be
  8.    EmployeeNumber = Text1.Text
  9.    Section = Text2.Text
  10.    Position = Text3.Text
  11.  
  12. ' no square brackets around EmployeeNumber, Section or Position
  13. ' as these are variables and not field or control names.
  14.    strSQL = "INSERT INTO TABLE1 (EmployeeNumber, Section, Position) " & _
  15.    "VALUES ('" & EmployeeNumber & "','" & Section & "','" & Position & "')"
  16.  
  17.    DoCmd.RunSQL strSQL
  18.  
  19. Adodc1.RecordSource = strSQL
  20. Adodc1.Recordset.Save
  21. Adodc1.Refresh
  22.  
  23. End Sub
  24.  
Mary
Newbie
 
Join Date: Nov 2006
Location: Dasmariņas, Cavite
Posts: 27
#3: Dec 12 '06

re: SQL in ACCESS and VB6


Quote:

Originally Posted by mmccarthy

Try this ...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. Dim EmployeeNumber As String
  3. Dim Section As String
  4. Dim Postion As String
  5. Dim strSQL As String
  6.  
  7. ' Wrong way around Julius, should be
  8.    EmployeeNumber = Text1.Text
  9.    Section = Text2.Text
  10.    Position = Text3.Text
  11.  
  12. ' no square brackets around EmployeeNumber, Section or Position
  13. ' as these are variables and not field or control names.
  14.    strSQL = "INSERT INTO TABLE1 (EmployeeNumber, Section, Position) " & _
  15.    "VALUES ('" & EmployeeNumber & "','" & Section & "','" & Position & "')"
  16.  
  17.    DoCmd.RunSQL strSQL
  18.  
  19. Adodc1.RecordSource = strSQL
  20. Adodc1.Recordset.Save
  21. Adodc1.Refresh
  22.  
  23. End Sub
  24.  
Mary


Thans mary, but there an erro about Refresh, well anyway i'll try to fix eat, but if i cant , may be i'll go to you ... thanks Godbless you

julius
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,875
#4: Dec 12 '06

re: SQL in ACCESS and VB6


Quote:

Originally Posted by OldSchool

Thans mary, but there an erro about Refresh, well anyway i'll try to fix eat, but if i cant , may be i'll go to you ... thanks Godbless you

julius

Try replacing Refresh with Requery
Reply