Check if ADODB Recordset contains multiple criteria ? Vba - vba

I would like to check if my recordset contains multiple criteria. I tried with the .Find with a filter :
filter2 = "[Nom] = '" & oLookFullName & "'" And "[nomEntreprise] = '" & objContact.CompanyName & "'"
rs.MoveFirst
rs.Find filter2, 1, adSearchForward
but after few researches, it authorizes just one criteria. My question is there an alternative to do it and how ?
EDIT
Find Method (ADO)
https://learn.microsoft.com/en-us/sql/ado/reference/ado-api/find-method-ado?view=sql-server-ver15
Only a single-column name may be specified in criteria. This method
does not support multi-column searches.

Try to modify the search criteria a bit:
filter2 = "[Nom] = '" & oLookFullName & "' And [nomEntreprise] = '" & objContact.CompanyName & "'"
rs.MoveFirst
rs.Find filter2, 1, adSearchForward

Related

Access DlookUp not working with multiple Criteria

The Dlookup Function is Giving me a syntax error I have tried multiple ways but none worked
x = DLookup("Clock_ID", "User_access", "Clock = " '" & Me.Clock_ID & _
& " AND Module = '" & Me.m_1 & "'")
I basically Need it to check 2 fields in the same table at the same time so the ID can be duplicated But the Module cant be duplicated.
I guess ID is numeric, so try:
x = DLookup("Clock_ID", "User_access", "Clock = " & Me.Clock_ID & " AND Module = '" & Me.m_1 & "'")

Access VBA Docmd.OpenQuery Can Run an update query but Currentdb.Excecute Cannot

I created a saved update query as below, which has control values and IIf function.
UPDATE SYS_AAAA_AAAH
SET SYS_AAAA_AAAH.AAK = AAA & " " & AAB & IIf(IsNull(AAC),"","(" & AAC & ")") & IIf(IsNull(AAF),""," not null") & " comment '" & AAH & "',"
WHERE (((SYS_AAAA_AAAH.AAO)=[forms]![frmAdmiTabl]![CombSAAO]));
DoCmd.OpenQuery can run it while Currentdb.Execute gives an error message 'too few parameters'. I created another saved update query without input from control or function and Currentdb.Execute worked. I don't want to see the warning message from Docmd.OpenQuery and I dont want to mess around by turning on and off the warning. Anyway of getting Currentdb.Execute work on this?
When you want to update a column of some certain records with another column's value and IIf function, it is better to use DAO.recordset edit and update
Dim Rs_AAAH As DAO.Recordset
Set Rs_AAAH = CurrentDb.OpenRecordset("select * from Table where AAO='" & Me.CombSAAO.Value & "'", dbOpenDynaset)
Rs_AAAH.MoveFirst
Do Until Rs_AAAH.EOF
With Rs_AAAH
.Edit
.Fields("AAK").Value = Rs_AAAH.Fields("AAA") & " " & Rs_AAAH.Fields("AAB") & IIf(IsNull(Rs_AAAH.Fields("AAC")), "", "(" & Rs_AAAH.Fields("AAC") & ")") & IIf(IsNull(Rs_AAAH.Fields("AAF")), "", " not null") & " comment '" & Rs_AAAH.Fields("AAH") & "',"
.Update
End With
Rs_AAAH.MoveNext
Loop
Rs_AAAH.Close
Set Rs_AAAH = Nothing

Crystal Report, how to use two condition selection formula?

Crystal Report, how to use two condition selection formula?
i want to use my Employee ID and the Date for the condition.
how can i combine the two?
CrystalReportViewer1.SelectionFormula = "{PayrollHistory.ID} ='" & txtempid.Text() & "'"
and
CrystalReportViewer1.SelectionFormula = "{PayrollHistory.EndDate} ='" & txtDate.Text() & "'"
You can concatenate conditions with AND :
CrystalReportViewer1.SelectionFormula = "{PayrollHistory.ID} ='" & txtempid.Text() & "' AND {PayrollHistory.EndDate} = '" & txtDate.Text()

VBA SQL Syntax Problems

I have the following SQL:
SQL = "UPDATE [TBLTMP] SET TBLTMP24 '" & Me.TOWN & "' WHERE TBLTMP00 = '" & "1" & "';"
Table name TBLTMP
Field to update TBLTMP24
Record to update TBLTMP00
I want to store the value of ‘Me.Town’ in the field TBLTMP24 which is in the table TBLTMP, record number 1, anyone have any ideas what might work?
You're missing an = in your SQL Statement after TBLTMP24. You're statement should be:
SQL = "UPDATE [TBLTMP] SET TBLTMP24 = '" & Me.TOWN & "' WHERE TBLTMP00 = '" & "1" & "';"
I think all you need is to add = into your query, like below:
SQL = "UPDATE TBLTMP SET TBLTMP24 = '" & Me.TOWN & "' WHERE TBLTMP00 = '" & "1" & "';"
If you want to change some columns add commas, like below:
SQL = "UPDATE TBLTMP SET TBLTMP24 = '" & Me.TOWN & "', another_col = '" & Me.another & "' WHERE TBLTMP00 = '" & "1" & "';"

Selecting data based on multiple fields (Where And)

I have large amounts of data that I am trying to sort out based on two cascading combo boxes. I get error Microsoft Access can't find the field '|1' referred to in your expression and it points me to:
ElseIf [Forms]![Send To GE]![cboFil] = "LCP" Then
strSQL = "Select * From [To_GE] Where [Community] = " & Chr(34) & Me.cboSubFil.Value & Chr(34) And [LCP] = "& Chr(34) & Me.cboSSubFil.Value & Chr(34)"
Set rst = db.OpenRecordset(strSQL)
It seems that the And should work for this. What's causing this error, and how can I resolve it?
strSQL = "Select * From [To_GE] Where [Community] = " & Chr(34) & Me.cboSubFil.Value & Chr(34) And [LCP] = "& Chr(34) & Me.cboSSubFil.Value & Chr(34)"
Should maybe be
strSQL = "Select * From [To_GE] Where [Community] = " & Chr(34) & Me.cboSubFil.Value & Chr(34) & " And [LCP] = " & Chr(34) & Me.cboSSubFil.Value & Chr(34)
To make things read a little easier though I would recommend escaping your quotes or switching to single quotes in the query
strSQL = "Select * From [To_GE] Where [Community] = '" & Me.cboSubFil.Value & "' And [LCP] = '" & Me.cboSSubFil.Value & "'"