DLookUp Function not match - database

Why when I write code like this the result doesn't match the table?
Code:
=DLookUp("Quiz","Grade_Fall_2022","Program_ID= '" & DLookUp("ID","Program","Program= '" & [Text_Program1] & "'") & "'" And "TIS_ID= " & [Text_ID])
Result: https://i.stack.imgur.com/c84Xh.png
Source Table: https://i.stack.imgur.com/aywZE.png

Try with:
=DLookUp("Quiz","Grade_Fall_2022","Program_ID = '" & DLookUp("ID","Program","Program = '" & [Text_Program1] & "'") & "' And TIS_ID = " & [Text_ID])

Related

DateTime field not Updateable

Here's my code:
strSQL = "UPDATE tblTransactions SET Verifier = '" & strUserName & "' WHERE PatientAccountNumber = '" & Me.PatientAccountNumber & "'"
strSQL = "UPDATE tblTransactions SET VerifierAssgnDate = #" & Date & "# WHERE PatientAccountNumber = '" & Me.PatientAccountNumber & "'"
"Verifier" updates fine, but "VerifierAssignDate" throws a "field not updateable" error. It's a DateTime field.
Thanks!
You can and should combine these (and VerifierAssgnDate was probably misspelled):
strSQL = "UPDATE tblTransactions " & _
"SET Verifier = '" & strUserName & "', VerifierAssignDate = Date() " & _
"WHERE PatientAccountNumber = '" & Me.PatientAccountNumber & "'"

Vbnet Sql incorrect syntax near ')'

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Try
con.ConnectionString = "Data Source=DESKTOP-3H4F5GB\MURATS;Initial Catalog=CRM;Integrated Security=True"
con.Open()
cmd.Connection = con
cmd.CommandText = "UPDATE Firma SET (Sektor = '" & ComboBox1.Text & "', Tip = '" & ComboBox2.Text & "', Telefon = '" & MaskedTextBox1.Text & "', Web = '" & TextBox2.Text & "', Adres = '" & RichTextBox2.Text & "', OSB = '" & ComboBox3.Text & "', PR = '" & ComboBox4.Text & "', Sehir = '" & ComboBox5.Text & "', Ulke = '" & ComboBox6.Text & "', Note = '" & RichTextBox1.Text & "', Durum = '" & ComboBox7.Text & "', Email ='" & TextBox3.Text & "') WHERE Firma = '" & ComboBox8.Text & "'"**
cmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show("Error while inserting record on table..." & ex.Message, "Insert Records")
Finally
con.Close()
End Try
End Sub
Your error is clearly on this line
cmd.CommandText = "UPDATE Firma SET (Sektor = '" & ComboBox1.Text & "', Tip = '" & ComboBox2.Text & "', Telefon = '" & MaskedTextBox1.Text & "', Web = '" & TextBox2.Text & "', Adres = '" & RichTextBox2.Text & "', OSB = '" & ComboBox3.Text & "', PR = '" & ComboBox4.Text & "', Sehir = '" & ComboBox5.Text & "', Ulke = '" & ComboBox6.Text & "', Note = '" & RichTextBox1.Text & "', Durum = '" & ComboBox7.Text & "', Email ='" & TextBox3.Text & "') WHERE Firma = '" & ComboBox8.Text & "'"**
You have to remove the () from the Update statement to be like the below
cmd.CommandText = "UPDATE Firma SET Sektor = '" & ComboBox1.Text & "', Tip = '" & ComboBox2.Text & "', Telefon = '" & MaskedTextBox1.Text & "', Web = '" & TextBox2.Text & "', Adres = '" & RichTextBox2.Text & "', OSB = '" & ComboBox3.Text & "', PR = '" & ComboBox4.Text & "', Sehir = '" & ComboBox5.Text & "', Ulke = '" & ComboBox6.Text & "', Note = '" & RichTextBox1.Text & "', Durum = '" & ComboBox7.Text & "', Email ='" & TextBox3.Text & "' WHERE Firma = '" & ComboBox8.Text & "'"
remove your open and close parenthesis on:
cmd.CommandText = "UPDATE Firma SET (Sektor = '" & ComboBox1.Text & "', Tip = '" & ComboBox2.Text & "', Telefon = '" & MaskedTextBox1.Text & "', Web = '" & TextBox2.Text & "', Adres = '" & RichTextBox2.Text & "', OSB = '" & ComboBox3.Text & "', PR = '" & ComboBox4.Text & "', Sehir = '" & ComboBox5.Text & "', Ulke = '" & ComboBox6.Text & "', Note = '" & RichTextBox1.Text & "', Durum = '" & ComboBox7.Text & "', Email ='" & TextBox3.Text & "')
answer
cmd.CommandText = "UPDATE Firma SET Sektor = '" & ComboBox1.Text & "', Tip = '" & ComboBox2.Text & "', Telefon = '" & MaskedTextBox1.Text & "', Web = '" & TextBox2.Text & "', Adres = '" & RichTextBox2.Text & "', OSB = '" & ComboBox3.Text & "', PR = '" & ComboBox4.Text & "', Sehir = '" & ComboBox5.Text & "', Ulke = '" & ComboBox6.Text & "', Note = '" & RichTextBox1.Text & "', Durum = '" & ComboBox7.Text & "', Email ='" & TextBox3.Text & "'
and some addition try to learn to use parametized queries comment if you want to learn.

Incorrect SQL syntax pointing at empty bottom row

I have a set of data that I upload to SQL and since a couple of new columns have been added (abandoned IVR & answered IVR) it is failing to upload properly.
The data will now only land in the temp table and not the full data one, but what makes it all the more confusing is that it's saying their is a syntax error of ',' on the bottom line which is blank
This is my merge statement which is when I debug is saying where the potential error is. But I don't understand why the error is pointing at a blank row and stopping the upload from happening?
Could anyone give me any pointers, apologies for the code layout - I don't know how to set it out.
Thanks
Dan
sSQL = "MERGE [C3 ODS].Telephony AS Target USING (SELECT CallDate,VDN,VDN_Name,Skill,Skill_Name,Telephony_Lookup,Site,Team,SubTeam,Client, '" & _
" Scheme,Calls_Offered,Calls_Answered,Calls_Abandoned,Calls_Abandoned_SLA,Calls_Answered_SLA,Average_TalkTime,Average_ACW,Average_HandleTime, '" & _
" Average_AbandonTime,Average_SpeedAnswer,TelephonySystem,TimePeriod1,TimePeriod2,TimePeriod3,TimePeriod4,TimePeriod5,TimePeriod6,TimePeriod7, '" & _
" TimePeriod8,TimePeriod9,Abandon1,Abandon2,Abandon3,Abandon4,Abandon5,Abandon6,Abandon7,Abandon8,Abandon9,Abandon10,Answered1,Answered2, '" & _
" Answered3,Answered4,Answered5,Answered6,Answered7,Answered8,Answered9,Answered10,DataLoad_Date,ClientGroup,LOB,ServiceLevel,Section, '" & _
" ForecastGroup,AbandonedIVR,AnsweredIVR FROM [C3 ODS].Telephony_Temp) AS Temp " & _
" ON Target.CallDate = Temp.CallDate AND Target.Telephony_Lookup = Temp.Telephony_Lookup WHEN MATCHED THEN UPDATE SET Target.Calls_Offered = Temp.Calls_Offered, '" & _
" Target.Calls_Answered = Temp.Calls_Answered, Target.Calls_Abandoned = Temp.Calls_Abandoned, Target.Calls_Abandoned_SLA = Temp.Calls_Abandoned_SLA, '" & _
" Target.Calls_Answered_SLA = Temp.Calls_Answered_SLA, Target.Average_TalkTime = Temp.Average_TalkTime, Target.Average_ACW = Temp.Average_ACW, '" & _
" Target.Average_HandleTime = Temp.Average_HandleTime, Target.Average_AbandonTime = Temp.Average_AbandonTime, Target.Average_SpeedAnswer = Temp.Average_SpeedAnswer, '" & _
" Target.VDN_Name = Temp.VDN_Name, Target.Skill_Name = Temp.Skill_Name, Target.Site = Temp.Site, Target.Team = Temp.Team, Target.SubTeam = Temp.SubTeam, '" & _
" Target.ClientGroup = Temp.ClientGroup, Target.Client = Temp.Client, Target.Scheme = Temp.Scheme " & _
" WHEN NOT MATCHED THEN INSERT (CallDate,VDN,VDN_Name,Skill,Skill_Name,Telephony_Lookup,Site,Team,SubTeam,Client,Scheme,Calls_Offered,Calls_Answered, '" & _
" Calls_Abandoned,Calls_Abandoned_SLA,Calls_Answered_SLA,Average_TalkTime,Average_ACW,Average_HandleTime,Average_AbandonTime,Average_SpeedAnswer, '" & _
" TelephonySystem,TimePeriod1,TimePeriod2,TimePeriod3,TimePeriod4,TimePeriod5,TimePeriod6,TimePeriod7,TimePeriod8,TimePeriod9,Abandon1,Abandon2, '" & _
" Abandon3,Abandon4,Abandon5,Abandon6,Abandon7,Abandon8,Abandon9,Abandon10,Answered1,Answered2,Answered3,Answered4,Answered5,Answered6,Answered7, '" & _
" Answered8,Answered9,Answered10,DataLoad_Date,ClientGroup,LOB,ServiceLevel,Section,ForecastGroup,AbandonedIVR,AnsweredIVR) " & _
" VALUES (Temp.CallDate, Temp.VDN, Temp.VDN_Name, Temp.Skill, Temp.Skill_Name, Temp.Telephony_Lookup, Temp.Site, Temp.Team, Temp.SubTeam, '" & _
" Temp.Client, Temp.Scheme, Temp.Calls_Offered, Temp.Calls_Answered, Temp.Calls_Abandoned, Temp.Calls_Abandoned_SLA, Temp.Calls_Answered_SLA, '" & _
" Temp.Average_TalkTime, Temp.Average_ACW, Temp.Average_HandleTime, Temp.Average_AbandonTime, Temp.Average_SpeedAnswer, Temp.TelephonySystem, '" & _
" Temp.TimePeriod1, Temp.TimePeriod2, Temp.TimePeriod3, Temp.TimePeriod4, Temp.TimePeriod5, Temp.TimePeriod6, Temp.TimePeriod7, Temp.TimePeriod8, '" & _
" Temp.TimePeriod9, Temp.Abandon1, Temp.Abandon2, Temp.Abandon3, Temp.Abandon4, Temp.Abandon5, Temp.Abandon6, Temp.Abandon7, Temp.Abandon8, '" & _
" Temp.Abandon9, Temp.Abandon10, Temp.Answered1, Temp.Answered2, Temp.Answered3, Temp.Answered4, Temp.Answered5, Temp.Answered6, Temp.Answered7, '" & _
" Temp.Answered8, Temp.Answered9, Temp.Answered10, Temp.DataLoad_Date, Temp.ClientGroup, Temp.LOB, Temp.ServiceLevel, Temp.Section, '" & _
" Temp.ForecastGroup, Temp.AbandonedIVR, Temp.AnsweredIVR);"
Cn.Execute sSQL

Syntax error in SQL query for MS Access

I am making the form to insert the records in table. I am unable to run this query as it is showing me the syntax error. I tried lot but not able to find the error. My query is as follow.
CurrentDb.Execute "
INSERT into Database2Sample(
nyu_id, location1, location2,
first_name, middle_name, last_name,
full_name, instructor_sis_id, instructor_email,
intstructor_net_id, personal_email, CV_link,
employee_nyu_global_site, highest_degree, degree_subject_area,
degree_status, degree_granting_institution, accomplishments,
Other_employee, WSQ_home_campus, teaching_language_course)
VALUES
('" & Me.nyu_id & "', '"
& Me.location1 & "', '"
& Me.location2 & "', '"
& Me.first_name & "', '"
& Me.middle_name & "', '"
& Me.last_name & "', '"
& Me.full_name & "', '"
& Me.instructor_sis_id & "', '"
& Me.instructor_email & "', '"
& Me.intstructor_net_id & "', '"
& Me.personal_email & "', '"
& Me.CV_link & "', '"
& Me.employee_nyu_global_site & "', '"
& Me.highest_degree & "', '"
& Me.degree_subject_area & "', '"
& Me.degree_status & "', '"
& Me.degree_granting_institution & "', '"
& Me.accomplishments & "', , '"
& Me.Other_employee & "', '"
& Me.WSQ_home_campus & "', '"
& Me.teaching_language_course & "')"
You have two commas in your value between accomplishments and employee field.
'" & Me.accomplishments & "', , '" & Me.Other_employee & "'
Delete any one of them will make it work.

Visual Studio Database custom criteria search wont work

I have created a database in Visual Studio and I am coding with VB.net I have created textboxes and checkboxes to match the fields that each will search when the search button is pressed .
whenever i perform a search using the text boxes and checkbox i get an error.
Item Name , Room , Broken, In Use, floor, are the fields searched by the tehe text in NameSearch, RoomSearch, BrokenSearchare, InUseSearch ,FloorSearchrespectivly ....etc
this is thee code for the search button
Private Sub SearchButton_Click(sender As Object, e As EventArgs) Handles SearchButton.Click
RecordDataGridView.Refresh()
Me.RecordBindingSource.Filter = "[Item Name]= '" & NameSearch.Text & "' And [Room]= '" & RoomSearch.Text & "' And [Make]= '" & MakeSearch.Text & _
"' And [Broken]= '" & BrokenSearch.CheckState & "' And [Replaced]= '" & ReplacedSearch.CheckState & "'And [ID#]= '" & IdentificationNumberSearch.Text & _
"' And [Floor]= '" & FloorSearch.Text & "' And [In Use]= '" & InUseSearch.CheckState & "'"
Me.RecordTableAdapter.Fill(Me.MLGDatabaseDataSet.Record)
RecordDataGridView.Refresh()
End Sub
the error
for example I enter a text into item nameSearch and floorSearch and press search ,no result will be turned up as the other text boxes have no text in them.
Without addressing other issues, such as using a parameterized query to prevent SQL injections or using StringBuilder to more efficiently perform concatenation, I believe your issue may be a missing space in this snippet:
ReplacedSearch.CheckState & "'And [ID#]= '"
if you change this to
ReplacedSearch.CheckState & "' And [ID#]= '"
it may resolve the immediate error. However, you almost certainly have additional logic errors introduced by the OR statement in the middle (you probably want to surround the two clauses that are ORed with parentheses).
I spotted the same thing as #competent_tech. I would set it up this way to make it easier to debug.
Dim strFilter As String = _
"[Item Name]= '" & NameSearch.Text & _
"' And [Room]= '" & RoomSearch.Text & _
"' And [Make]= '" & MakeSearch.Text & _
"' And [Broken]= '" & BrokenSearch.CheckState & _
"' Or [Replaced]= '" & ReplacedSearch.CheckState & _
"' And [ID#]= '" & IdentificationNumberSearch.Text & _
"' And [Floor]= '" & FloorSearch.Text & _
"' And [In Use]= '" & InUseSearch.CheckState & "'"
Debug.Print(strFilter)
RecordBindingSource.Filter = strFilter
Edit: you want to filter only when there are conditions given
'filter string
Dim strFilter As String = ""
'for check boxes you probably want to filter only if checked
If BrokenSearch.CheckState = CheckState.Checked Then strFilter += "And [Broken]= " & BrokenSearch.CheckState & " "
If ReplacedSearch.CheckState = CheckState.Checked Then strFilter += "And [Replaced]= " & ReplacedSearch.CheckState & " "
If InUseSearch.CheckState = CheckState.Checked Then strFilter += "And [In Use]= " & InUseSearch.CheckState & " "
'for text boxes you want to filter only if has text
If IdentificationNumberSearch.Text.Length > 0 Then strFilter += "And [ID#]= '" & IdentificationNumberSearch.Text & "' "
If FloorSearch.Text.Length > 0 Then strFilter += "And [Floor]= " & FloorSearch.Text & " "
If RoomSearch.Text.Length > 0 Then strFilter += "And [Room]= " & RoomSearch.Text & " "
If MakeSearch.Text.Length > 0 Then strFilter += "And [Make]= '" & MakeSearch.Text & "' "
If NameSearch.Text.Length > 0 Then strFilter += "And [Item Name]= '" & NameSearch.Text & "' "
'check to make sure there is at least one condition
If strFilter.Length > 0 Then
'remove the first "And"
strFilter = strFilter.Remove(0, 4)
'output
Debug.Print(strFilter)
'set to filter
RecordBindingSource.Filter = strFilter
End If
Edit: Your error "Cannot perform '=' operation on System.Boolean and System.String" I think the problem is that the filter value has to match the field type.
For strings do this: [Make] = 'stringValue' using single quotes;
For integers do this: [Floor] = 24 without single quotes;
For bit do this: [Broken] = 1 without single quotes;
It looks like Broken, Replaced and In Use are Bit type in the database. And I'm guessing that Floor and Room are Integer.

Resources