Im starting to pull my hair out.
I am looking to do a multi criteria dsum that looks at the current user and todays date.
Tried many variations but must be missing something very simple so any help is appreciated
StatusBox = DSum("[Task_time]", "[tbl_Data]", "[CDP] = '" & Environ("username") & "' and [Record_Date] = '" & Date & "'")
Dates must be enclosed with #. Also they need to be formatted in order to return the desired result.
Try this:
StatusBox = DSum("[Task_time]", "[tbl_Data]", "[CDP] = '" & Environ("username") & "' and [Record_Date] = #" & Format(Date, "mm/dd/yyyy") & "#")
You are just making it slightly too complicated:
StatusBox = DSum("[Task_time]", "[tbl_Data]", "[CDP] = '" & Environ("username") & "' And [Record_Date] = Date()")
Related
I am so sorry for bothering you with maybe a fundamental and easy question; I need to change a positive value to a negative, this value is in the table (MSACCESS) I canĀ“t figure out how to do it. I have been playing with the symbols but still nothing. The code is here:
Qry = "UPDATE QuickCash SET Pagado = 'S', TipoPago = '" & PymntType & "' Cantidad = '" & (Abs(Cantidad) * -1) & "' WHERE Folio = '" & grdDataGrid.Columns(0).Text & "'"
I have been querying, then changing and then updating but that isn't very pleasant...
Thank you in advance
I found out the issue, I missed a semicolon and the use of symbols was wrong. Here is the correct code.
Qry = "UPDATE QuickCash SET Pagado = 'S', TipoPago = '" & PymntType & "' , Cantidad = (Abs(Cantidad) * -1) " _
& "WHERE Folio = '" & grdDataGrid.Columns(0).Text & "'"
Sorry for the inconvenience, I hope this code can help someone else.
Thank you.
Trying to apply 2 filters at the same time to a subform.
Want to see records between DATES X and Y, and from BRANCH Z only.
Working fine alone, but can't use both at the same time. I know it's something
Current code:
Private Sub Command39_Click()
If IsNull(Me.txtFrom) Or IsNull(Me.txtTo) Then
MsgBox "Insert date!"
Else
With Me.frmDailyRevenue.Form
.Filter = "[DateDbl] BETWEEN " & Me.txtFromDbl & " AND " & Me.txtToDbl & "" And [F5] = " & Me.cboBranch & """
.FilterOn = True
End With
End If
End Sub
This is basically bits of code I got from the web as I'm really new to this.
So, all advice is welcome.
Try this:
.Filter = "[DateDbl] BETWEEN #" & Format(Me.txtFromDbl,"mm\/dd\/yyyy") & _
"# AND #" & Format(Me.txtToDbl,"mm\/dd\/yyyy") & "# And [F5] = '" & Me.cboBranch & "'"
I supposed that Me.cboBranch is text. If this field contains code, remove single quotes.
Also I noticed that controls you check and controls you take data from are different (Me.txtFrom and Me.txtFromDbl, Me.txtTo and Me.txtToDbl), check this.
Found the problem.
Using BETWEEN and AND for the date range was causing some conflict with the second AND to add the filter for field F5.
So I switched to use >= and <= as follows:
.Filter = "[DateDbl] >= " & Me.txtFromDbl & " AND [DateDbl] <= " & Me.txtToDbl & " AND [F5] = " & Me.cboBranch & ""
Just to clarify, for people that might come for this later, you should use # as Sergey pointed out if you have a date field, my date is in double format, so I don`t need to.
Thanks,
I have the following ms access query. I want it to query with the gender (female or male) selected from the combo box. At the moment, when I select "female", the query results also includes all male persons.
How should I format this code:
WHERE (((Q_Gender_Statistics.Year) Like [cboYear] & "*") AND ((Q_Gender_Statistics.Gender) Like "*" & [cboGender] & "*"))
Don't use Like if not needed:
" WHERE Q_Gender_Statistics.Year = " & [cboYear] & " AND Q_Gender_Statistics.Gender = '" & [cboGender] & "'"
If cboGender looks up "Male/Female" form an index value, try this:
" WHERE Q_Gender_Statistics.Year = " & [cboYear] & " AND Q_Gender_Statistics.Gender = " & [cboGender] & ""
I have a form that allows people to add new employees but they need to be able to edit or update the existing employees as well.
So I added a button to allow them to make changes right on the form, click the update button and the record they were working on would be updated right away.
When I tested it however the string runs and even pops up a warning letting you know you are about to permanently change a record. But then it throws up an error stating "did not update record due to Key Violation"
I have included my "On Click" Event code
DoCmd.RunSQL "UPDATE EntList " & _
"SET EntList.BusinessUnit = '" & Me.cboBUnit & "', EntList.EntityName = '" & Me.txtEntName & "', EntList.Position = '" & Me.txtPos & "', EntList.Location = '" & Me.cboLoc & "', EntList.Client = '" & Me.cboClient & "', EntList.Dept = '" & Me.cboDept & "', EntList.DistKey = '" & Me.txtDistKey & "', EntList.Salary = '" & Me.txtSalary & "', Entlist.Currency = '" & Me.cboCurrency & "', EntList.[SG&A] = '" & Me.txtSG_A & "', EntList.BillRate = '" & Me.txtBillRate & "', EntList.[Util%] = '" & Me.txtUtil_ & "', EntList.MeritDate = '" & Me.txtMeritDate & "', EntList.[Merit%] = '" & Me.txtMerit_ & "' " & _
"WHERE EntList.EntityID = '" & Me.txtEntID.Value & "';"
I am wondering what I am missing that is causing this error.
If I followed the comments correctly, you have resolved the key violation error which occurred because one of the update values did not satisfy the requirement of a defined relationship which enforces referential integrity. In that situation, Access reports the relationship violation as key violation.
And, with that problem resolved, you're now facing a type mismatch between an update value and the destination field.
Your UPDATE included quotes around every value it supplied. Likely the current error is because a destination field is numeric data type instead of text.
So you can examine the data type of each destination field and make sure your UPDATE includes quotes around the values for text fields, # around the values for Date/Time fields, and no delimiters around the values for numeric fields.
While that is possible, it's also time-consuming and error-prone. A better approach is to use a parameter query so you needn't fiddle with delimiters.
Here is an abbreviated sample of the approach I'm suggesting. You will have to extend it to include the other fields I left out.
Dim strUpdate As String
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
strUpdate = "UPDATE EntList AS e" & vbCrlf & _
"SET e.BusinessUnit = pBusinessUnit, " & _
"e.EntityName = pEntityName" & vbCrLf & _
"WHERE e.EntityID = pEntityID;"
Debug.Print strUpdate
Set db = CurrentDb
Set qdf = db.CreateQueryDef(vbNullString, strUpdate)
qdf.Parameters("pBusinessUnit") = Me.cboBUnit.Value
qdf.Parameters("pEntityName") = Me.txtEntName.Value
qdf.Parameters("pEntityID") = Me.txtEntID.Value
qdf.Execute dbFailOnError
Set qdf = Nothing
Set db = Nothing
I have a Form in Access which uses a selection from a combo box list to drive the creation of a report.
The combo box selection is evaluated as an ID. I need to get it as a text. I've found other similar issues but cannot get it to work. Can anyone walk me through it?
The closest thread I found was http://www.access-programmers.co.uk/...ad.php?t=58062, but not sure what "joining to the lookup table" entails.
In the code below, txtExpr1001, txtIndustry, and txtSkill are the combo boxes.
The code:
Private Sub cmdSubmit_Click()
Dim sWhereClause As String
sWhereClause = "Expr1001 = '" & txtExpr1001.Value & "' AND MonthsCon >= " & txtMonth1.Value & " AND IndustryName = '" & txtIndustryName.Value & "' AND MonthsNonCon >= " & txtMonth2.Value & " AND Skill = '" & txtSkill.Value & "' AND MonthsSkills >= " & txtMonth3.Value & ""
Call DoCmd.OpenReport("IndustryCon + IndustryNonCon + Skills", acViewPreview, , sWhereClause)
End Sub
My code does not trigger an error. The report opens but it's blank.
If you want to get the value of a combo box (which I'm not sure which of your .values are the combo box if any are) then you can just write something like this:
Private Sub cmdSubmit_Click()
Dim sWhereClause As String
'Me.Combo_BoxName.Column(0) is going to be how you call the combo box
'I put it right at the front of the string and chose ID as a random name as well
sWhereClause = "ID = '" Me.Combo_BoxName.Column(0) & "' AND Expr1001 = '" & txtExpr1001.Value & "' AND MonthsCon >= " & txtMonth1.Value & " AND IndustryName = '" & txtIndustryName.Value & "' AND MonthsNonCon >= " & txtMonth2.Value & " AND Skill = '" & txtSkill.Value & "' AND MonthsSkills >= " & txtMonth3.Value & ""
Call DoCmd.OpenReport("IndustryCon + IndustryNonCon + Skills", acViewPreview, , sWhereClause)
End Sub