Modules & VBA :: How To Run Multiple SQL Commands On Click Of A Button
Jul 25, 2013
I want to run multiple SQL commands on click of a button. I have these three command,
CurrentDb.Execute "INSERT INTO UserMadeDeviceT(Product, ORESector) " & _
" VALUES ('" & Me.D_NewDeviceTxt & "', '" & Me.D_ORECmb & "')"
CurrentDb.Execute "INSERT INTO UserMadeDeviceT (RatedKilowattPower, KilogramWeight)" & _
" SELECT RatedKilowattPower, Weight FROM UserSelectedComponentT " & _
" WHERE [TotalComponent] = '" & D_ComponentNameCmb & "'"
CurrentDb.Execute "INSERT INTO UserMadeDeviceT (Cost) SELECT SUM (EuroCost) FROM UserSelectedComponentT"
all of these work indevidually and return the correct value but the add three rows to the table. How can I combine these three commands into one so that it will only add one entry?
I made a database that in one of the forms, I like by clicking on a button the user be able to select 5 excel files with different file names (in the same directory) and then based on the imported file's names, it be stored in 5 different tables.
At the moment by using the bellow code, I can import multiple files (with the same formats) only into one table . My vba code comes as follow:
Function GetAllFiles() Dim fd As Object Dim strFilter As String Dim lngItems As Long
Const msoFileDialogOpen As Long = 3 Const msoFileDialogViewDetails As Long = 2
I work for a company that manufactures home appliances & electronics. When those products fail within the warranty period, we are obligated to repair the units for the customers.
We have around 200 factory technicians who make those repairs. Each tech is able to make approximately 8 repairs each day. We have a dispatching system that assigns the repairs to the techs based on their availability each day. But the problem is that we have to manually enter and adjust the schedule for all 200 techs every single day, and this takes a lot of time. And of course technicians get sick, take vacation, etc, so we have to adjust the schedule so no techs will be assigned calls when they're off.
The problem: For example, currently when a technician takes off for 2 weeks, the user has to enter 14 individual records for the tech, which is somewhat time consuming. What I need is to program a button click event to determine the two dates (startDate & endDate) and append multiple records from one single entry in the form for each date in between and including the two date fields.
I know I'll probably need to create a loop that will loop through the two dates on the form and append a record for each day, so I can then cross reference the dates to the master schedule dates to make sure that no availability is opened for the techs taking time off.
Multiple IF functions in a form. I have a button that on click will print a report if certain fields in the form have data in them. If not, a msgbox pops up to let the user know that data must be filled and then sets focus on whichever field needs data in the form. There are many IF statements, and they all work fine until I get to a certain one then the remaining IF does not continue.
Here is some code:
If IsNull([Alert]) Then MsgBox "An alert time is required." _ , vbCritical, "Data Required" Me.Text591.SetFocus Exit Sub Else If IsNull([Enroute]) Then
[Code] .....
The next IF argument will bring up the msgbox when there is no data, thats great. However, when the user fills in the field and continues with the button click to print the report, the button does nothing.
Here is the next IF, the one with the problem:
If IsNull([Combo608]) Then If IsNull([Combo620]) Then MsgBox "You must select either a planned event or an emergency event." _ , vbCritical, "Information" Me.Combo608.SetFocus Exit Sub Else
How to get it to work, to continue with the remaining IF arguments after this one (there are several more)?
Or are there a better way to code this and not have the many IF arguments?
I have a table with many records, using a form with an update button click event, I would like to update ALL records where the Item in the table = the Item in the form.
There are 6 checkboxes and 6 text boxes that will need to be updated, but right now I am just trying to test if i can even change one text box to keep it simple. I have tried to start by using this:
Code: Dim mySQL As String Dim ItemNo As String Dim SO As String
mySQL = "UPDATE BT200 SET Part = '" & SO & "' WHERE Item = " & ItemNo DoCmd.RunSQL mySQL
So every time i run this command button, it gives me a prompt "You are about to update 0 row(s)". Nothing gets updated at all, I am clearly missing something vital here.
I have created a query that has the info for a quick search. What I want to do is create a form that I type the last name of my customer and then click a button that opens the query and filters out all records that don't match the criteria I enter. I want the button on the form to do both. Is thie possible? If so how? Please Help. Very much appreciated
the login is working perfectly, once It logs in there is a button to expand all that is based in JS. I can't seem to work out how to get it to click the button to expand the whole menu, latest code is below:
Code:
Option Explicit Function Checkpage() Dim IE As Object Dim lform As Object Dim Document As Object Dim item As Object
I have created a button that works fine however it will only work one click per form load and i cant seem to figure out why.
Code: Private Sub BntExpired_Click() Dim QryAllCourses As recordset Do Until ExpiryDate > Date Or ExpiryDate = "" MsgBox ([FirstName].Value + " " + [SecondName].Value + "'s course in " + [CourseName].Value + " has expired") recordset.MoveNext Loop Exit_BntExpired_Click: Exit Sub Err_BntExpired_Click: MsgBox Err.Description Resume Exit_BntExpired_Click End Sub
I have a textbox with about 400 characters, I also have 5 textboxes next to it. I want to click a button and I want to transfer the characters to the other textboxes 208 characters at a time.
Is it possible in access, to create a button that will copy a file to a new directory? Specifically, the data field in question is an access hyperlink that we can click on to open a PDF drawing of a part. I just want to copy the file the hyperlink points to, into a new directory.
The above code works and my issue is how can I move the mouse to the OK button and click on it to. The reason why is when I SETTEXT to the address bar it does not refresh so I SETTEXT to the file name box to navigate to the prescribe address which will refresh the navigation bar once the OK button is clicked. How to refreshing the navigation bar.
I have a mainform with a combobox and a button. What i want is when i click on the combobox and then on the button I want that the textbox in the subform automatically fill in.
The mainform name is FrmTakenInvoerenEnToewijzenAanEenMonteur,
I have access table that stores details as attached. Just to give an example how data is stored , I copied data from Access table to excelsheet. Now I would like to create a report that will run when a button is clicked on the form and the vba code should display the last 7 dates from todays dates in the report along with all the data and colour the record Green,Amber and Red depending upon the Update Date and Target Date. If the Target date exceeds then that records should be coloured "Red" and if todays date equals to Date then the record should be amber and if greater than Date but less than Target Date then it should be Green.
So the report should display the last 7 dates records from todays date and the appropriate color of each record to let everyone know if its under target, meets target etc.
I would like to be able to click a button on a form in my data base and login to a website using my username and password.
The manual login, requires two clicks after username and password, "Login" and "Click to continue"
I have tried many solutions found on the internet, none work for me. One forum reply was to send me a link to another site and it was for Excel. Is the code the same? Didn't work anyway.
From the website I want to login to, I have copied the code into a Word doc from the "inspect element" to work out the names of the fields I'm trying to put my username and password into. (see attached)
I would also like to be able to use Google Chrome as my web browser if possible?
There is a button on the form that allows users to send email with the form as an attachment in pdf. I'd like to create a date/time stamp in another table called tblLog. Trouble is the code works uptil sending emails but it doesn't record the stamp.
I have a database that had some code that enabled the user to click a button and it would take information from one Access query or table and paste it into specific locations in Excel. This is important because the last worksheet has specific formatting in place.
If it didn't, I'd just use the transfer spreadsheet option and not even bother opening Excel at all with code.
I've got it working well except for the last part. The last query being copied has eight records and only one is being sent to Excel. Same code as the other queries where all of their data is going to the right spot in Excel with the right number of records.
Getting error '2450' when click Access close button to exit.
Run-time error '2450': ECN cannot find the referenced form 'frmLogin'.
Note: After login my login form is visible to, cause to get login user id into "frmECN" Form. But When I'm in "frmECN" Form and enter data then close to exit Access main close button I'm getting 2450 error.
In the Main Form , I have few buttons and I am writing the following code to open the right form when a button is clicked but unfortunately the code isn't doing anything. No form is opening. I am using MS office 2010.
Code: Private Sub BtnOption_Click() DoCmd.OpenForm "Form1", acNormal, , , acFormAdd, acDialog End Sub Private Sub Form_Load() 'Me!Label1.Caption = "Welcome " & Environ("username") & "!"
I have a button which runs a list of queries that take roughly 10 seconds to run, when another user clicks the button while the other one is running it gives and error message 3405, File already in use.