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

how to save the value of unbound text boxes to field in table

P: 8
hiiii
i have form(Main form) that contain textboxes(f1,f2) and a button (f3)
when enter values to text boxes and click the button i want
the values saved in fields(Passwords,Names) that Exists in table called(Passwords)


thanks in advance
Mar 8 '13 #1

✓ answered by Seth Schrock

That is because you have them in two separate INSERT queries. You need to combine them into one, like this:
Expand|Select|Wrap|Line Numbers
  1. Dim sql As String
  2. Dim LName As String
  3. Dim LNa As String
  4. Dim db as DAO.Database
  5.  
  6. set db = CurrentDb
  7.  
  8. LNa = Me.f1.Value
  9. LName = Me.f2.Value
  10.  
  11.      If Not IsNull(LName) And Not IsNull(LNa) Then
  12.           sql = "INSERT INTO Passwords ([Passwords], [Names]) VALUES ('" & LName & "', '" & LNa & "')"
  13.  
  14.           db.Execute (sql)
  15.  
  16.      Else
  17.           MsgBox "Please enter the password"
  18.           Exit Sub
  19.      End If

Share this Question
Share on Google+
7 Replies


Seth Schrock
Expert 2.5K+
P: 2,939
Here is a link to the MSDN website that shows the Recordset.AddNew method: Recordset.AddNew Method (DAO). You would just use something like
Expand|Select|Wrap|Line Numbers
  1. rst![Field_Name] = Me![Control_Name]
to pass the values in the controls to the proper fields.
Mar 8 '13 #2

P: 8
thank you so much
please can u help me in my code
Expand|Select|Wrap|Line Numbers
  1.  Dim sql As String
  2. Dim sq As String
  3.      Dim LName As String
  4.   Dim LNa As String
  5.  
  6.   LNa = Me.f1.Value
  7.      LName = Me.f2.Value
  8.  
  9.      If Not IsNull(LName) And Not IsNull(LNa) Then
  10.           sql = "INSERT INTO Passwords ([Passwords]) VALUES ('" & LName & "')"
  11.  
  12.                CurrentDb.Execute (sql)
  13.                 sq = "INSERT INTO Passwords ([Names]) VALUES ('" & LNa & "')"
  14.  
  15.                CurrentDb.Execute (sq)
  16.  
  17.  
  18.  
  19.      Else
  20.           MsgBox "Please enter the password"
  21.           Exit Sub
  22.      End If
  23.  
Mar 8 '13 #3

P: 8
the value of the name and password save in separately records
i want to store them in the same record
Mar 8 '13 #4

mshmyob
Expert 100+
P: 903
You only need a single INSERT statement.

Expand|Select|Wrap|Line Numbers
  1. sql = "INSERT INTO Passwords (Passwords, Names) VALUES ('" & LName & "','" & LNa & "')"
  2.  
cheers,
Mar 8 '13 #5

Seth Schrock
Expert 2.5K+
P: 2,939
That is because you have them in two separate INSERT queries. You need to combine them into one, like this:
Expand|Select|Wrap|Line Numbers
  1. Dim sql As String
  2. Dim LName As String
  3. Dim LNa As String
  4. Dim db as DAO.Database
  5.  
  6. set db = CurrentDb
  7.  
  8. LNa = Me.f1.Value
  9. LName = Me.f2.Value
  10.  
  11.      If Not IsNull(LName) And Not IsNull(LNa) Then
  12.           sql = "INSERT INTO Passwords ([Passwords], [Names]) VALUES ('" & LName & "', '" & LNa & "')"
  13.  
  14.           db.Execute (sql)
  15.  
  16.      Else
  17.           MsgBox "Please enter the password"
  18.           Exit Sub
  19.      End If
Mar 8 '13 #6

P: 8
thanks very much for your answers
Mar 8 '13 #7

P: 6
thank you for this code
Mar 8 '13 #8

Post your reply

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