My Form has a List Box that need to be updated when someone type stuff in ComboPC,ComboFOPT&txtRiskPT. Also, the Table [Product Types2] needs to be updated.
I have a command button [New] with the following code: -
-
Private Sub New_Click()
-
-
Dim stDocName As String
-
-
stDocName = "INSERT INTO [Product Types2] ([Product Classification],[Front Office Product Type],[Risk Product Type]) VALUES ('" & ComboPC.Value & "','" & ComboFOPT.Value & "','" & txtRiskPT & "')"
-
DoCmd.RunSQL stDocName
-
-
End Sub
-
-
It works the first time, but not when you want to add the 2nd new row.
5 12833
You need to requery the list box each time. -
-
Private Sub New_Click()
-
Dim strSQL As String ' Just a naming convention
-
-
strSQL = "INSERT INTO [Product Types2] ([Product Classification],[Front Office Product Type],[Risk Product Type]) VALUES ('" & ComboPC.Value & "','" & ComboFOPT.Value & "','" & txtRiskPT & "')"
-
-
DoCmd.RunSQL strSQL
-
-
Me.ListBoxName.Requery
-
-
End Sub
-
-
Thank you MMcCarthy, I appreciate it, but it still doesn't work. The first time the Form is opened and a row is added it works, and after that it doesn't want to add a new row. Any other suggestions, Please? One of my other forms with exactly the same code does work, though...
Thank you MMcCarthy, I appreciate it, but it still doesn't work. The first time the Form is opened and a row is added it works, and after that it doesn't want to add a new row. Any other suggestions, Please? One of my other forms with exactly the same code does work, though...
Is it possible that the problem lies in the underlying table rather than the list box. Are you trying to add data that would violate the unique index of a field. What is the table structure?
my table has no indexes/primary keys. I found a solution, though: the difference between the firste forms (that works) and the second, was that the first reads the info to insert into table, out of text boxes, the second has one combo box to read from, thus, I wrote the value in the combo box to a text box, and from there, inserted it into the table! - Private Sub Combo51_BeforeUpdate(Cancel As Integer)
-
txtBook.Value = Combo51.Value
-
txtBook.Requery
-
End Sub
-
-
Private Sub New_Click()
-
'DoCmd.SetWarnings False
-
-
Dim strDisplay As String
-
Dim intResponse As Integer
-
Dim strPrompt As String
-
Dim stDocName As String
-
-
If Focussed.Value = True Then strDisplay = "Yes"
-
If Focussed.Value = False Then strDisplay = "No"
-
-
txtID = ""
-
If txtID = "" Or IsNull(txtID) Then
-
stDocName = "INSERT INTO [Product Type p Portfolio2] (Book,[Front Office Product Type],[Focussed Area?]) VALUES ('" & txtBook.Value & "','" & [FO PT].Value & "','" & Focussed.Value & "')"
-
DoCmd.RunSQL stDocName
-
Me.List55.Requery
-
-
End If
-
-
End Sub
-
Don't know if this is the only answer, but it worked for now. Thank you for your help, MMcCarthy!
my table has no indexes/primary keys. I found a solution, though: the difference between the firste forms (that works) and the second, was that the first reads the info to insert into table, out of text boxes, the second has one combo box to read from, thus, I wrote the value in the combo box to a text box, and from there, inserted it into the table! - Private Sub Combo51_BeforeUpdate(Cancel As Integer)
-
txtBook.Value = Combo51.Value
-
txtBook.Requery
-
End Sub
-
-
Private Sub New_Click()
-
'DoCmd.SetWarnings False
-
-
Dim strDisplay As String
-
Dim intResponse As Integer
-
Dim strPrompt As String
-
Dim stDocName As String
-
-
If Focussed.Value = True Then strDisplay = "Yes"
-
If Focussed.Value = False Then strDisplay = "No"
-
-
txtID = ""
-
If txtID = "" Or IsNull(txtID) Then
-
stDocName = "INSERT INTO [Product Type p Portfolio2] (Book,[Front Office Product Type],[Focussed Area?]) VALUES ('" & txtBook.Value & "','" & [FO PT].Value & "','" & Focussed.Value & "')"
-
DoCmd.RunSQL stDocName
-
Me.List55.Requery
-
-
End If
-
-
End Sub
-
Don't know if this is the only answer, but it worked for now. Thank you for your help, MMcCarthy!
____________________
This solution is not working for me, The tables are getting updated by what i put after single quotes ,
INSERT INTO CHILDPROJECT ( MASTERPROJECT, CHILDPROJECT )
VALUES (' " & mprj.value " ', ' " &chprj.value & " ');
this inserts "&mprj.value&" and " &chprj.value & "
Can u plz suggest some , its urgent.!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Si |
last post by:
Hi Guys
I am using this code to execute an Access VBA function from ASP:
strDbName = strDataSource & "data\webjobs.mdb"
Set objAccess = Server.CreateObject("Access.Application")...
|
by: Dutchy |
last post by:
Hi there,
After spending several hours trying all I could imagine and search for in
Google I gave up. In a continuous form I want to sort the choosen column by
clicking the header (label) of...
|
by: sea |
last post by:
I have a database in Access 2002 but I am unable to view code or write
any modules when logged in with a limited user account using Windows
XP, service pack 2 -- no problems when logging in as...
|
by: Namratha Shah \(Nasha\) |
last post by:
Hey Guys,
Today we are going to look at Code Access Security.
Code access security is a feature of .NET that manages code depending on its
trust level. If the CLS trusts the code enough to...
|
by: Cheryl Langdon |
last post by:
Hello everyone,
This is my first attempt at getting help in this manner. Please
forgive me if this is an inappropriate request.
I suddenly find myself in urgent need of instruction on how to...
|
by: garry.oxnard |
last post by:
Can anyone help me to solve a problem which involves switching from
Access to Excel (then back to Access) programatically please?
I have an Excel template which, on open, also opens an Access...
|
by: peridian |
last post by:
Hi,
I have the below code to transfer code modules between Access database files. I have three problems, only one of which is annoying.
a) How do you prevent the Save As box from appearing...
|
by: colemanj4 |
last post by:
Here is what I have so far, it loops while the PW is incorrect, or
until cancel is selected. I want it to lock the tables for adds,
deletes, and edits when cancel is selected, and if the PW is...
|
by: lovecreatesbea... |
last post by:
Do you check all error conditions for all library calls in you code?
Is it necessary to check all errors? Is it convenient to check all
errors (or how to make code clean and readable with mass of...
|
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
|
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...
|
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...
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |