I have two update statements:
Dim newvalue As Integer
sSQL = "UPDATE Workstations SET SID = 0 WHERE SID = txtID3"
DoCmd.RunSQL sSQL
AND
Dim strsql As String
strsql = "UPDATE Workstations SET [SID] = " & newvalue & " WHERE [Workstation ID] = '" & selectedwks & "'"
DoCmd.RunSQL strsql
When I run my code, it prompts me with two yes/no windows right after another saying whether if I want to update the table or not.
Is it possible to write those two update statements together so that I'm only prompted once? If yes, how should I do it?
Thanks in advance
I do not see these two update statements as being compatible. You are potentially (and quite likely) targeting two different rows (or sets of rows if SID and [Workstation ID] are not unique).
If you are are actually trying to target a row where the SID AND [WorkStation ID] are a match on what the user inputs, then just change your WHERE clause to include both columns separated by AND. Else, I am not sure you can logically accomplish what you're asking.
Related
I am trying to perform some OLEDB commands between a list of dictionary values and an access database. I am wondering if it is possible to check if one column in the access database matches the key of a dictionary, if you find the key that matches check the keyvalue in the dictionary to the access database quantity in another column. I am just wondering if this is possible since I am new to the SQL in vb.net commands.
I wanted to run these two queries but I am not sure if this is even possible. I tried to find some documents on this but I came out short. Anything would help!
sqlQry = "SELECT Column1 FROM [Table] WHERE Column1 = '" & Key & "' "
sqlQry = "SELECT Column2 FROM [Table] WHERE Column2 < " & Value & " "
I send out a newsletter each month and would like to record the contact id, date sent in a separate table. This table will record a history of all the newsletter sent. What is the best way to do this...Append to table or just create a do loop and add new records?
This should be pretty easy. Now, you didn't say is you are appending records into Access, or SQL Server, or something else. The example below assumes you are using Access, but you can easily modify the code just slightly to insert into any kind of structured database.
Dim dbs As DAO.Database
Set dbs = OpenDatabase("Full path to your db")
'You can then "execute" a SQL statement:
dbs.Execute "INSERT INTO Employees(Name, Number) VALUES('" & Worksheets("Sheet1").Range("A2").Value & "','" & Worksheets("Sheet1").Range("A3") & "')"
I am with a little bit of a coding problem that I don't know how to solve. I want to put in the table as a record a field name of another table in the same Database.
I will give you an example:
Table1
What I have
Table 2
What I want
The table 1 is update weekly from an external source so I need to record the field name as a record in the second table using VBA language. Does anybody knows if it's possible?
Thank You in advance
You could do something like this
Dim db As Database
Dim fld As Field
Dim sql As String
Set db = CurrentDb
For Each fld In db.TableDefs("YourTable").Fields
sql = "Insert into YourSummaryTable([Date], Hours) select '" & fld.Name & "', sum([" & fld.Name & "]) as s from YourTable"
DoCmd.RunSQL sql
Next fld
Note that you've used a reserved word Date as a fieldname, which isn't best practice and requires the use of the square brackets in the query.
I have searched for a question that I am having, though I find parts of the answer I am not able to understand it fully. I am using access2010.
In simple Terms, I want to filter a table [newsearch] to show the results based on my WHERE condition.
I can use SELECT and a WHERE condition and I get a result through a query, but I want this result to be saved into [newsearch], that means I want this [newsearch] to contain only the results of this query.
I tried using SELECT INTO but since my source and destination are [newsearch], it does not work.
the query I run now is:
strSQL = "SELECT * FROM [newsearch] WHERE [newsearch].[" & Me.Combo17 & "] = '" & Me.Text18 & "'"
Set qdef = db.CreateQueryDef("User query results", strSQL)
qdef.close
Set qdef = Nothing
Set db = Nothing
DoCmd.OpenQuery "User query results", acViewNormal
This gives me the result in a query table but I want it saved to [newsearch].
How can I do it?
select into query creates a table, but obviously you cannot create a table that already exists. You have 2 options:
Instead of selecting what you need, delete those records from your table that you do not need: delete from [newsearch] where field3<>xyz
You can use select into to create a new table, then drop [newsearch] and then rename the new table to [newsearch].
I have a linked table called [Part Number] and locally, users need to be able to select a check box (Yes/No) field corresponding to the part number to perform actions on it with other commands. Currently, to have the check box in the displayed query, I have a separate local table that maintains a list of all of the part numbers in [Part Number] that pairs them with a check box that is then rolled into the displayed query. What I would like to do is have a query that just directly queries [Part Number] and adds it's own Yes/No field to get rid of the table that has to be constantly updated to make sure all part numbers are accounted for.
I know this is possible for text fields:
SELECT
[Part Number].Concatenate,
[Part Number].[Part Nbr] & " " & Date() AS [Select]
FROM [Part Number];
A field called "Select" will be added to the query with the part number and the date next to it. I want that field to be a Yes/No field.
Edit:
I don't want the [Part Number] table to have the Yes/No field on it because it is shared between multiple users and will interfere with actions the database takes based on selections. I also would like to not use a table at all since the parts list changes frequently and the front end table would have to be constantly be getting updated from the back end table [Part Number] to ensure everything works properly. Having a select query based on the [Part Number] table would automatically update every time the parts list changes since it's a query, not a table. This query would be rolled into the displayed query that ties together several tables and queries.
As #DonJewett said, this is not possible for Yes/No checkbox fields. Your best bet is to do it the way you are doing; it's easiest to just clear the Yes/No table and repopulate it every time you open the form.
(on Form_Load() of your selection form, frmMultiSelect):
Dim strSQL As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM tblNodes")
'Clear current links
strSQL = "DELETE * FROM tblMultiSelect"
db.Execute strSQL
'Create '0' state links for every node in tblNodes
rs.MoveFirst
Do Until rs.EOF = True
strSQL = "INSERT INTO tblMultiSelect(node_id, selected) "
strSQL = strSQL & "VALUES (" & rs![node_id] & ", 0);"
db.Execute strSQL
rs.MoveNext
Loop
'Update subform
Me.frmMultiSelect.Requery