Hi,
I am trying to run a delete sql statement. i want it to delete from a list box, and delete the one which is currently selected.
i have tried a few things, but hane not had success
Please help[
16 13904
Hi,
I am trying to run a delete sql statement. i want it to delete from a list box, and delete the one which is currently selected.
i have tried a few things, but hane not had success
Please help[
What have you tried?
Hi,
I am trying to run a delete sql statement. i want it to delete from a list box, and delete the one which is currently selected.
i have tried a few things, but hane not had success
Please help[
What is the row source of the listbox (in SQL)?
My list is called lstViewRequest, and this is i have added a delete query into is, and right now, it will ask you for the record you weant to delete.
this is the code: - Private Sub cmdSaveRecord_Click()
-
-
strSQL = "DELETE * " & _
-
"FROM [tblRequest] " & _
-
"WHERE (([tblRequest].[Request ID])=([Please Enter The Job You Have Accpeted])) ;"
-
'"WHERE (([tblRequest].[Request ID])=([lstViewRequest].[Request ID])) ;"
-
DoCmd.RunSQL strSQL
-
-
On Error GoTo Err_cmdSaveRecord_Click
-
-
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
-
-
Exit_cmdSaveRecord_Click:
-
-
Err_cmdSaveRecord_Click:
-
-
Exit Sub
-
MsgBox Err.Description
-
Resume Exit_cmdSaveRecord_Click
-
End Sub
You can't refer to the selected item on the list like this - ([lstViewRequest].[Request ID])
Try something like this ... -
Private Sub cmdSaveRecord_Click()
-
On Error GoTo Err_cmdSaveRecord_Click
-
Dim strSQL As String
-
-
strSQL = "DELETE * " & _
-
"FROM [tblRequest] " & _
-
"WHERE [tblRequest].[Request ID]=" & Me![lstViewRequest]
-
DoCmd.RunSQL strSQL
-
Me![lstViewRequest].Requery ' requery the list
-
-
Exit_cmdSaveRecord_Click:
-
-
Err_cmdSaveRecord_Click:
-
Exit Sub
-
MsgBox Err.Description
-
Resume Exit_cmdSaveRecord_Click
-
-
End Sub
-
Mary
that still asks for the ID as well, but this time, the message that pops up is the name this is linked with the record ID.
so if record 10 is selected, the the name (i.e. Frank) comes up on the message box.
Is there no way for that message box not to come up, but jus remove automatically
that still asks for the ID as well, but this time, the message that pops up is the name this is linked with the record ID.
so if record 10 is selected, the the name (i.e. Frank) comes up on the message box.
Is there no way for that message box not to come up, but jus remove automatically
The listbox is obviously bound to the name and not the ID.
What is the Row Source SQL of the listbox?
What is the Bound Column Set to?
this is the sql statement: - SELECT tblRequest.[Request ID], tblRequest.[Request By], tblRequest.[Request Description], tblRequest.[Requested Date], tblRequest.Budget, tblRequest.[Duration (Hours)] FROM tblRequest;
-
and youre right, it is bounded to column 2, the name field.
Will I have to remove that list, and add another list, and make it have no bounds
this is the sql statement: - SELECT tblRequest.[Request ID], tblRequest.[Request By], tblRequest.[Request Description], tblRequest.[Requested Date], tblRequest.Budget, tblRequest.[Duration (Hours)] FROM tblRequest;
and youre right, it is bounded to column 2, the name field.
Will I have to remove that list, and add another list, and make it have no bounds.
The reason why i bounded it is so that the information on that filed goes there.
I was typing sql insert statements in sql, but it wasnt working.
basically, i have two lists there, both which add to the actual form (wihci is linked to the a job table). The first list box adds the person who is going to participate in that job, and the second list adds the service that is being provided for that job.
this is the sql statement:
SELECT tblRequest.[Request ID], tblRequest.[Request By], tblRequest.[Request Description], tblRequest.[Requested Date], tblRequest.Budget, tblRequest.[Duration (Hours)] FROM tblRequest;
and youre right, it is bounded to column 2, the name field.
Will I have to remove that list, and add another list, and make it have no bounds
Just set the Bound column to column 1 and try running the code I gave you again.
Just set the Bound column to column 1 and try running the code I gave you again.
If i bind it there, it wont enable me to add whats in that field to the required field. - Private Sub AddItem()
-
Dim Nrec As Integer ' Number of records with item (=0 or 1)
-
Dim intJobID As Integer
-
Dim ServiceUser As String
-
Dim ServiceProvider As String
-
Dim ServiceUsed As String
-
Dim strRequests As String
-
Dim strServices As String
-
Dim strRequestCriteria As String
-
Dim strServiceCriteria As String
-
Dim strSQL As String
-
'
-
' If no item is selected, then dispaly warning message and exit sub
-
'
-
If IsNull(lstRequests) Then
-
MsgBox vbCrLf & "You must select a Request" & _
-
vbCrLf & vbCrLf, vbExclamation, "Grid Accounting & Billing System"
-
-
Exit Sub
-
End If
-
-
'intJobID = [Job ID]
-
ServiceUser = lstRequests
-
ServiceUsed = lstServices
-
ServiceProvider = lstServices
-
strCriteria = "([Job ID]=" & intJobID & ") And ([Service User]= '" & ServiceUser & "') AND ([Service Used]= '" & ServiceUsed & "' AND ([Service Provider]= '" & ServiceProvider & "')"
-
-
strSQL = "INSERT INTO [tblJobs]([JobID], [Service Used], [Service Provider], [Service User], [Start Date], [Duration]) " & _
-
"VALUES (forms![FrmJobs].[Job ID], forms![frmJobs].lstServices.Column(1), forms![frmJobs].lstServices.Column(2), forms![frmJobs].lstServices.Column(2), forms![FrmJobs].lstRequests.Column(4), forms![FrmJobs].lstRequests.Column(6),1);"
-
-
DoCmd.RunSQL strSQL
-
End Sub
Change to ... -
Private Sub cmdSaveRecord_Click()
-
On Error GoTo Err_cmdSaveRecord_Click
-
Dim strSQL As String
-
-
strSQL = "DELETE * " & _
-
"FROM [tblRequest] " & _
-
"WHERE [tblRequest].[Request ID]=" & Me![lstViewRequest].Column(0)
-
DoCmd.RunSQL strSQL
-
Me![lstViewRequest].Requery ' requery the list
-
-
Exit_cmdSaveRecord_Click:
-
-
Err_cmdSaveRecord_Click:
-
Exit Sub
-
MsgBox Err.Description
-
Resume Exit_cmdSaveRecord_Click
-
-
End Sub
-
In code the columns start at 0
Mary
yay. thank you very much. it works.
PS: wen an update or a delte query is run, message box comes up confirming this, is there a possible way to avoid or stop these messages from comming up
You're welcome. The following additions will turn the warning off for the duration of the query. -
Private Sub cmdSaveRecord_Click()
-
On Error GoTo Err_cmdSaveRecord_Click
-
Dim strSQL As String
-
-
DoCmd.SetWarnings False
-
strSQL = "DELETE * " & _
-
"FROM [tblRequest] " & _
-
"WHERE [tblRequest].[Request ID]=" & Me![lstViewRequest].Column(0)
-
DoCmd.RunSQL strSQL
-
Me![lstViewRequest].Requery ' requery the list
-
-
DoCmd.SetWarnings True
-
-
Exit_cmdSaveRecord_Click:
-
-
Err_cmdSaveRecord_Click:
-
Exit Sub
-
MsgBox Err.Description
-
Resume Exit_cmdSaveRecord_Click
-
-
End Sub
-
Mary
Thank you.
Sorry to be a bother, but i have one more question.
i have a login page, where members can log, and their user name and password is fetched from the members table.
I want to have 2 different authorisation level.
One members authorisation, so wen they login, only their records will show up, no others, and they cannot access it as well, and one admin level, where obviously they can do whateva they please.
Any suggestions?
You're welcome. The following additions will turn the warning off for the duration of the query. -
Private Sub cmdSaveRecord_Click()
-
On Error GoTo Err_cmdSaveRecord_Click
-
Dim strSQL As String
-
-
DoCmd.SetWarnings False
-
strSQL = "DELETE * " & _
-
"FROM [tblRequest] " & _
-
"WHERE [tblRequest].[Request ID]=" & Me![lstViewRequest].Column(0)
-
DoCmd.RunSQL strSQL
-
Me![lstViewRequest].Requery ' requery the list
-
-
DoCmd.SetWarnings True
-
-
Exit_cmdSaveRecord_Click:
-
-
Err_cmdSaveRecord_Click:
-
Exit Sub
-
MsgBox Err.Description
-
Resume Exit_cmdSaveRecord_Click
-
-
End Sub
-
Mary
Hi,
i have used this code and found it very useful so thankyou very much.
however when i click to delete the item from the list, a Message box appears asking me to enter a prameter value. If the value entered is exactly the same as item chosen on the list then the item is removed, otherwise 0 items get removed. have i not done something right?
any help gratefully received,
Thanks
Hello, hooijdonk.
Please refrain from posting your questions in another member's thread in the future. It results in your question not being viewed nor understood. This is also called thread hijacking and isn't allowed per the site rules. Go ahead and start a new thread explaining your situation and if needed include a hyperlink to the old thread but copying the URL in your browser's URL window, at the top of the Message window on this site you will see an icon that looks like a globe. Clicking on it will show the URL tag dialog box. Paste your URL in the second window of the dialog box and click OK.
Thanks,
Scott MODERATOR
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Vipin Kedia |
last post by:
Hi
I have written a code for showing the list boxes as selected using a
Listitem and the selected property of the items.
Now I have 2 list boxes in my page. But it shows only the selected values...
|
by: Moe Sizlak |
last post by:
Hi There,
I am trying to return the value of a listbox control that is included as a
user control, I can return the name of the control but I can't access the
integer value of the selected item,...
|
by: David J |
last post by:
Hi,
I am trying again, and seriously struggling. My problem is that I am trying
to set the selected value in a listbox equal to a value of a textbox, when
you op the listbox. I am not getting that...
|
by: jim Bob |
last post by:
Hi,
I have a form with a list box that shows the contents of a table and
managed to create an add record button with the wizard.
(DoCmd.GoToRecord , , acNewRec)
Now i want to make a delete...
|
by: acord |
last post by:
Hi,
I am having problem to get a value of the selected item from a dropdown
listbox.
Here is the JS function;
function getSelectedItem(objSelect) {
alert("in getSelectedItem");
alert...
|
by: John |
last post by:
I have a listbox that is databound when my form loads. A user
can then select and option using a drop down box. When the user
selects an option the corresponding items in the listbox gets selected....
|
by: Mitch |
last post by:
Is the following a correct representation of the relationship of the selected
index to selected item:
INDEX ITEM
0 "item 1"
1 "item 2"
2 "item 3"
and so on.
I keep...
|
by: rn5a |
last post by:
I am binding a DropDownList with records existing in a database table.
I want to add an extra item *SELECT COMPANY* at index 0 so that by
default, it gets selected. This is how I tried it but the...
|
by: compwizard |
last post by:
hello all,
Just a quick query
I currently have an hires form where clients place orders,
When an item is selected this would drop the item within a listbox and save within a itemhireline...
|
by: angelicdevil |
last post by:
i have listbox 1 which displays status , based on selection of status listbox 2 displays usernames. and based on username selected the textbox displays the email id.
its working fine till...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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:
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: 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...
| |