473,378 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

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

7 14715
Seth Schrock
2,965 Expert 2GB
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
aannll
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
aannll
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
904 Expert 512MB
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
2,965 Expert 2GB
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
aannll
8
thanks very much for your answers
Mar 8 '13 #7
thank you for this code
Mar 8 '13 #8

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

Similar topics

2
by: John Kreps | last post by:
(acc 2002) I've got six unbound text boxes on a subform that has a white background. Each of those six boxes has an expression that when true, will change its background from white to another...
2
by: Jayjay | last post by:
I've got a report that has a series of unbound text boxes that are being populated by some variables in code. The format is supposed to be a currancy format, but on a certain series of boxes, I...
7
by: Aravind | last post by:
Hi folks. I have 2 forms, frmBorrow and frmHistory frmBorrow has an unbound multi-column combo box (cboMember) and 7 unbound text boxes (MemNo, MemName, MemIC, MemType, CourseFaculty, Borrow,...
11
by: amanda27 | last post by:
I have a form and there are some text boxes that show a score depending on what someone picks in the drop down next to that box. I did this part with some coding and therefore, for example if they...
7
kcdoell
by: kcdoell | last post by:
Hello: I have a continous form that displays various forecasting records that an End user can add or edit the records (this feeds off of a query that I created called "ReQryForecast"). On that...
9
by: RICHARD BROMBERG | last post by:
Please bear in mind that I am a newbie. I am posting this question a second time because the responses to my earlier post were a little wide of the mark. So, here goes: I am using Access 2000...
11
by: jwessner | last post by:
I have a form (Form1) which contains basic Project data and a subform listing the personnel assigned to the Project as a continuous form. Selecting a person on that project and clicking on a command...
1
by: MyWaterloo | last post by:
I have an unbound text box on my main form that is used to show the sum totals in my sub form. I also have a field on my main form that has a control source in a table. This bound field needs to...
7
by: HSXWillH | last post by:
I am designing an inventory system and am stuck on a potential problem. I have a table of Stock_Catalog containing the following fields: Stock_ID (random autonumber), Full_Desc, Serial, Auto,...
2
topher23
by: topher23 | last post by:
Disclaimer: I've already come up with a solution for this issue, but I thought I'd post it in the hope that it could help someone else and on the off chance that someone has another solution. I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.