I am trying to create a new app that uses a SQL database to pull out data based on user input/selections.
For this I am using:
1 combo box that displays the projects
1 combo box that displays the available columns to be used while querying the table
1 text box in which the user can input data to complete the query requirements
Also I am using params to query the database as I found out this is the right way to do it (to avoid any unwanted SQL injection attacks).
So far the sub looks like this:
Private Sub FindItem()
SQL.AddParam("#item", "%" & TxtItem.Text & "%")
SQL.AddParam("#project", "%" & cbxproj.Text & "%")
SQL.AddParam("#column", "%" & cbxcol.Text & "%")
loadgrid("Select
SourceServer
,ProjectId
,ProjectName
,MasterTitle
,BugIdPrefix
,BugId
,BugTitle
,BugDescription
,EpicName
,Submitter
,AssignedByPerson
,IssueType
,Priority
,Severity
,PlatformFound
,ProgressStatus
,Resolution
,CloseReason
,Feature
,SubFeature
,FoundVersion
,AffectedVersion
,FixVersion
,GameArea
,BuildFound
,BuildFixed
,ClFixed
,Component
,Label
,CurrentOwner
,TestType
,TimeEstimated
,TimeRemaining
,TimeLogged
,Studio
,TestTeam
,ScrumTeam
,createdtime_utc as 'Date Created'
,assignedtime_utc as 'Date Assigned'
,closedtime_utc as 'Date Closed'
,lastmodifiedtime_utc as 'Date Last Modified'
From mydatabase where ProjectName like #project and #column like #item")
End Sub
So the issue is that if I select a project and a column and then press the search button, the results are displayed. Once I input some text in the text box, there are no results displayed whatsoever.
What am I doing wrong here?
Related
I have a unique index of fields in my table in microsoft access. The fields are Shift, Operator, Date_Field, and Machine. I have a data entry form with combobox selections for these fields, except for the date which autopopulates today's date. I want to be able to navigate the form te the record that matches the existing Shift/Operator/Date/Machine combo if it already exists. I have a DLookup function that checks to see if such a record exists already, but now I need to know how to change the form so it is entering the data on that record instead of a new one.
Here's what I have so far. It is being activated in the AfterUdate of one of the last combobox in the tab order.
Dim int_ID As Integer
With Me
'checks if duplicate record exists and stores it as int_ID variable
int_ID = Nz(DLookup("ID", "Tracking", "Shift= " & Val(.ShiftCbo) & " And Operator='" & .OpCbo.Column(1) & "' And Date_Field=#" & .DateBox & "# And Machine='" & .MachineCbo.Column(1) & "'"), 0)
End With
If int_ID <> 0 Then
'I need to know what to put here to take the form to the existing record.
End If
I've tried to use Cmd.GoToRecord but that doesn't work.
One of my favorite (and simplest) methods is using Me.Recordsource
Once you have your code working correctly which defines the filter criteria, try something like this:
Me.Recordsource= "select * from UnderlyingFormMainQuery where TextColumnName='" & varString & "' or NumericColumnName=" & intSomething
Me.Requery
Using a Form in MS Access, I need to ensure only unique records are entered into the table.
It's unfortunately in a situation where I can't enforce unique records via the table's primary keys.
I have the following code in the BeforeUpdate for the Form, but it is not working. Any help would be greatly appreciated!
Private Sub Form_BeforeUpdate(Cancel As Integer)
If DCount("*", "[Role_Details]", "[Role] = " & Me.[ComboRole] & " AND [Session] = " & Me.[ComboSession]) > 0 Then
MsgBox "Duplicate!"
Cancel = True
Me.[ComboSession].SetFocus
Exit Sub
End If
End Sub
Note: The table name is "Role_Details". Field names are "Role" and "Session". With "ComboRole" and "ComboSession" being the Form Field Labels.
Any thoughts on where I've gone wrong here?
Updates##
When I open the DataSheet Form, it presents a popup box saying "Enter Parameter Value" and "frm_Role_Details.Session". I'm not sure why this is, but I can enter past it and open the Form.
Then, them i'm entering a record an error pops up saying "Run-time error '2465': Can't find the field '|1' referred to in your expression. Both Fields are Text Strings. I'm at a loss!
When concatenating in VBA, text fields require apostrophe delimiters for inputs.
If DCount("*", "[Role_Details]", "[Role] = '" & Me.[ComboRole] & "' AND [Session] = '" & Me.[ComboSession] & "'")> 0 Then
Date/Time fields use # delimiter.
Number fields do not use any delimiter.
Essentially I would like to update a subforms column values with a name found in a combo box.
A table called "tbl_jobs" is the source behind the subform, the column I am trying to update is called "Person_Name".
The combo box is called "PersonCombo" .
I am working on creating a query called "updateRecord" using the Access query designer that is executed by the button "updateButton"
The following is how the query will be executed:
DoCmd.OpenQuery "updateRecord"
The content of the query is what I am having trouble with:
UPDATE tbl_jobs SET Person_Name = '" & PersonCombo & "' WHERE [Select] = True
Instead of filling the column data with the values from the chosen name in "PersonCombo" like Jamie, Mickey, Haley, etc. (values from PersonCombo) it just says " & PersonCombo & "
What is wrong with my syntax?
If this is a saved query, it doesn't know about the current form.
You need to use the full path to the control, but no concatenation, e.g.
UPDATE tbl_jobs SET Person_Name = Forms!myForm!PersonCombo WHERE [Select] = True
If the combo box is on a subform, refer to:
Forms: Refer to Form and Subform properties and controls
e.g. Forms!Mainform!Subform1.Form!ControlName
I do not believe you can pass a variable to a saved query. Instead build the query in code and run it:
dim SQL as string
PersonCombo = "thePerson"
SQL = "UPDATE tbl_jobs SET Person_Name = '" & PersonCombo & "' WHERE [Select] = True"
DoCmd.RunSQL SQL
Table of Documents:
Company Document Status Notes:
A 1 Submission Submitted on 12-12-12
A 1 Review Reviewed on 12-12-13
A 1 Adopted Adopted on 12-12-14
A 2 Submission Submitted on 01-01-01
A 2 Review Reviewed on 01-01-02
A 2 Adopted Adopted on 01-01-03
I have two combo boxes on a form; first combo box allows me to select the document and is linked up to the first query: e.g. Selecting '1' would return:
Company Document Status Notes:
A 1 Submission Submitted on 12-12-12
A 1 Review Reviewed on 12-12-13
A 1 Adopted Adopted on 12-12-14
The second combo box then allows me to select its' status and is linked up to the second query; the second query is used to filter the results from the first query: e.g. Selecting 'Adopted' would return:
Company Document Status Notes:
A 1 Adopted Adopted on 12-12-14
Lastly, I have a text box that displays the 'Notes' field based on your selection from both of the combo boxes. E.g. Selecting '1', and then 'Adopted' would display this in the text box:
'Adopted on 12-12-14'
I can edit the text (Note) that appears in the text box, but I want to assign a function to a button, that when clicked; will replace the 'Notes' field in the database with the text that is currently in the text box.
I've been searching for a while and can't seem to get anything working; I know the code will go in the click_event properties of the button; but I'm not sure what code to use exactly. In it's most standard form, I want this to happen when the button is clicked:
UPDATE Document(Table) SET Notes(Field)=textboxname.value
Any ideas?
The code below will allow you to enter text, then will execute the sql command to update notes in a record.
You will need to place this code inside your button click.
You need to change the names of the comboBoxes in the sql to use the names you have.
I assume there is not a unique key to use instead of 'document' and 'status'?
I certainly hope the document numbers never repeat across companies, else you will update multiple rows!
Private Sub cmdAddNote_Click()
Dim strNote As String
Dim strSQL As String
Dim dbs As DAO.Database
strNote = InputBox("Enter notes below, then click OK:", "Add Notes")
If strNote = "" Then
' Cancel
Else
strSQL = "UPDATE [Documents] SET [Documents].Notes = '" & strNote & "' " & _
"WHERE ((([Documents].[Document])= '" & cbo1 & "') AND (([Documents].[Status])='" & cbo2 & "'));"
Set dbs = CurrentDb
dbs.Execute strSQL
dbs.Close
Set dbs = Nothing
End If
End Sub
I have a word document macro enabled, I have a drop down button within the document which takes information from one form field and places it into another form field.
Select Case ActiveDocument.FormFields("Dropdown1").Result
Case "Order"
ActiveDocument.FormFields("ord1").Result ActiveDocument.FormFields("p1").Result
End Select
How can I adjust the code so that, instead of replacing everything in field "ord1" it would join the existing text within the field?
Try something simple like this:
ActiveDocument.FormFields("ord1").Result = _
ActiveDocument.FormFields("ord1").Result & " " & _
ActiveDocument.FormFields("p1").Result