By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,124 Members | 2,027 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,124 IT Pros & Developers. It's quick & easy.

SQL in ACCESS and VB6

P: 27
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

--------------------------------------------------------------------------------
Dec 12 '06 #1
Share this Question
Share on Google+
3 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
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
Dec 12 '06 #2

P: 27
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
Dec 12 '06 #3

MMcCarthy
Expert Mod 10K+
P: 14,534
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
Dec 12 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.