Related
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])
I get a run time 13 error = "mismatch error" in my login form in the Access Database.
Currently the form works for members and successfully logs them in however when I try to enter correct login details from the trainer table I get the run time error.
Option Compare Database
Private Sub Command1_Click()
If IsNull(Me.txtEmail) Then
MsgBox "Please Enter Email Address", vbInformation, "Email Requeired"
Me.txtEmail.SetFocus
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please Enter Email Address", vbInformation, "Email Requeired"
Me.txtPassword.SetFocus
Else
'process the job'
If (IsNull(DLookup("MemberEmail", "TBL_Members", "MemberEmail = '" & Me.txtEmail.Value & "' And MemberPassword = '" & Me.txtPassword.Value & "'")) Or (DLookup("TrainerEmail", "TBL_Trainers", "TrainerEmail = '" & Me.txtEmail.Value & "' And TrainerPassword = '" & Me.txtPassword.Value & "'"))) Then
MsgBox "Invalid Username or Password!"
Else
MemberEmail = DLookup("[MemberEmail]", "TBL_Members", "[MemberEmail] = '" & Me.txtEmail.Value & "'")
TrainerEmail = DLookup("[TrainerEmail]", "TBL_Trainers", "[TrainerEmail] = '" & Me.txtEmail.Value & "'")
SecurityLevel = DLookup("[SecurityLevel]", "TBL_Members", "[MemberEmail] = '" & Me.txtEmail.Value & "'")
DoCmd.Close
If (TempPass = "password") Then
MsgBox "Please change Password", vbInformation, "New password required"
DoCmd.OpenForm "frmUserinfo", , , "[UserLogin] = " & UserLogin
Else
'open different form according to user level
If SecurityLevel = 1 Then ' for Members
DoCmd.OpenForm "Admin"
Else
DoCmd.OpenForm "Navigation Form"
End If
End If
End If
End If
End Sub
Private Sub Form_Load()
Me.txtEmail.SetFocus
End Sub
Your problem is in this expression:
If (IsNull(DLookup("MemberEmail", "TBL_Members", "MemberEmail = '" & _
Me.txtEmail.Value & "' And MemberPassword = '" & Me.txtPassword.Value & "'")) _
Or (DLookup("TrainerEmail", "TBL_Trainers", "TrainerEmail = '" & _
Me.txtEmail.Value & "' And TrainerPassword = '" & Me.txtPassword.Value & "'"))) _
Then
Let's add some variables to make it easier to read:
Dim varM As Variant
Dim varT As Variant
varM = DLookup("MemberEmail", "TBL_Members", "MemberEmail = '" & _
Me.txtEmail.Value & "' And MemberPassword = '" & Me.txtPassword.Value & "'"))
varT = DLookup("TrainerEmail", "TBL_Trainers", "TrainerEmail = '" & _
Me.txtEmail.Value & "' And TrainerPassword = '" & Me.txtPassword.Value & "'"))
If (IsNull(varM Or varT)) Then
The problem is that Or requires Boolean or numeric operands, but you're applying it to e-mail addresses and then checking whether the result is null. What you really want to do is check whether each is null and then use the results of those expressions as the operands for Or:
If (IsNull(varM) Or IsNull(varT)) Then
Furthermore, as pointed out in a comment, the operator should be And, not Or, since you would never expect both of the values to be non-null:
If (IsNull(varM) And IsNull(varT)) Then
I'll leave it to you to figure out how to fix that in the original expression without the variables.
I need help figuring out why I'm getting this syntax error when trying to run this code in Microsoft Access. I am working on this database for work and have some experience with it, but not a whole lot.
I created a database before the one I'm currently working on and it works fine. It is very similar to the database that I'm working on now, so I just copied it and then renamed the fields and text boxes and everything to match the information that this database will be handling.
Essentially I have a table with the data and then I want a form that has a text box for each field in the table with a subtable of the main table incorporated into the form. The user fills in the text boxes with the information and then either adds it to the table or they can click on a record and edit it or delete it with the corresponding buttons on the form.
Now I'm getting a runtime error '3134': syntax error in INSERT INTO statement when trying to click the add button on one of my forms. This only happens on the add button and consequently the update button if it is set to update, but all of the other buttons work fine.
Here is the code for the new database:
Option Compare Database
Private Sub cmdAdd_Click()
'when we click on button Add there are two options
'1. for insert
'2. for update
If Me.txtICN.Tag & "" = "" Then
'this is for insert new
'add data to table
CurrentDb.Execute "INSERT INTO tblInventory(ICN, manu, model, serial, desc, dateRec, dateRem, dispo, project, AMCA, UL, comments) " & _
" VALUES(" & Me.txtICN & ", '" & Me.txtManu & "', '" & Me.txtModel & "', '" & Me.txtSerial & "', '" & Me.txtDesc & "', '" & Me.txtDateRec & "', '" & Me.txtDateRem & "', '" & Me.txtDispo & "', '" & Me.txtProject & "', '" & Me.txtAMCA & "', '" & Me.txtUL & "', '" & Me.txtComments & "')"
Else
'otherwise (Tag of txtICN store the ICN of item to be modified)
CurrentDb.Execute "UPDATE tblInventory " & _
" SET ICN = " & Me.txtICN & _
", manu = '" & Me.txtManu & "'" & _
", model = '" & Me.txtModel & "'" & _
", serial = '" & Me.txtSerial & "'" & _
", desc = '" & Me.txtDesc & "'" & _
", dateRec = '" & Me.txtDateRec & "'" & _
", dateRem = '" & Me.txtDateRem & "'" & _
", dispo = '" & Me.txtDispo & "'" & _
", project = '" & Me.txtProject & "'" & _
", AMCA = '" & Me.txtAMCA & "'" & _
", UL = '" & Me.txtUL & "'" & _
", comments = '" & Me.txtComments & "'" & _
" WHERE ICN = " & Me.txtICN.Tag
End If
'clear form
cmdClear_Click
'refresh data in list on form
frmInventorySub.Form.Requery
End Sub
Private Sub cmdClear_Click()
Me.txtICN = ""
Me.txtManu = ""
Me.txtModel = ""
Me.txtSerial = ""
Me.txtDesc = ""
Me.txtDateRec = ""
Me.txtDateRem = ""
Me.txtDispo = ""
Me.txtProject = ""
Me.txtAMCA = ""
Me.txtUL = ""
Me.txtComments = ""
'focus on ID text box
Me.txtICN.SetFocus
'set button edit to enable
Me.cmdEdit.Enabled = True
'change caption of button add to Add
Me.cmdAdd.Caption = "Add"
'clear tag on txtICN for reset new
Me.txtICN.Tag = ""
End Sub
Private Sub cmdClose_Click()
DoCmd.Close
End Sub
Private Sub cmdDelete_Click()
'delete record
'check existing selected record
If Not (Me.frmInventorySub.Form.Recordset.EOF And Me.frmInventorySub.Form.Recordset.BOF) Then
'confirm delete
If MsgBox("Are you sure you want to delete this item?", vbYesNo) = vbYes Then
'delete now
CurrentDb.Execute "DELETE FROM tblInventory " & _
"WHERE ICN =" & Me.frmInventorySub.Form.Recordset.Fields("ICN")
'refresh data in list
Me.frmInventorySub.Form.Requery
End If
End If
End Sub
Private Sub cmdEdit_Click()
'check whether there exists data in list
If Not (Me.frmInventorySub.Form.Recordset.EOF And Me.frmInventorySub.Form.Recordset.BOF) Then
'get data to text box control
With Me.frmInventorySub.Form.Recordset
Me.txtICN = .Fields("ICN")
Me.txtManu = .Fields("manu")
Me.txtModel = .Fields("model")
Me.txtSerial = .Fields("serial")
Me.txtDesc = .Fields("desc")
Me.txtDateRec = .Fields("dateRec")
Me.txtDateRem = .Fields("dateRem")
Me.txtDispo = .Fields("dispo")
Me.txtProject = .Fields("project")
Me.txtAMCA = .Fields("AMCA")
Me.txtUL = .Fields("UL")
Me.txtComments = .Fields("comments")
'store id of item in Tag of txtICN in case ICN is modified
Me.txtICN.Tag = .Fields("ICN")
'change caption of button add to Update
Me.cmdAdd.Caption = "Update"
'disable button edit
Me.cmdEdit.Enabled = False
End With
End If
End Sub
And here is the code for the old database:
Option Compare Database
Private Sub cmdAdd_Click()
'when we click on button Add there are two options
'1. for insert
'2. for update
If Me.txtID.Tag & "" = "" Then
'this is for insert new
'add data to table
CurrentDb.Execute "INSERT INTO tblEquipmentList(equipID, equipDesc, equipManu, equipModelNum, equipSerNum, lastCalDate, calDue) " & _
" VALUES(" & Me.txtID & ", '" & Me.txtDesc & "', '" & Me.txtManu & "', '" & Me.txtModelNum & "', '" & Me.txtSerNum & "', '" & Me.txtLastCalDate & "', '" & Me.txtCalDueDate & "')"
Else
'otherwise (Tag of txtID store the id of equipment to be modified)
CurrentDb.Execute "UPDATE tblEquipmentList " & _
" SET equipID = " & Me.txtID & _
", equipDesc = '" & Me.txtDesc & "'" & _
", equipManu = '" & Me.txtManu & "'" & _
", equipModelNum = '" & Me.txtModelNum & "'" & _
", equipSerNum = '" & Me.txtSerNum & "'" & _
", lastCalDate = '" & Me.txtLastCalDate & "'" & _
", calDue = '" & Me.txtCalDueDate & "'" & _
" WHERE equipID = " & Me.txtID.Tag
End If
'clear form
cmdClear_Click
'refresh data in list on form
frmEquipmentListSub.Form.Requery
End Sub
Private Sub cmdClear_Click()
Me.txtID = ""
Me.txtDesc = ""
Me.txtManu = ""
Me.txtModelNum = ""
Me.txtSerNum = ""
Me.txtLastCalDate = ""
Me.txtCalDueDate = ""
'focus on ID text box
Me.txtID.SetFocus
'set button edit to enable
Me.cmdEdit.Enabled = True
'change caption of button add to Add
Me.cmdAdd.Caption = "Add"
'clear tag on txtID for reset new
Me.txtID.Tag = ""
End Sub
Private Sub cmdClose_Click()
DoCmd.Close
End Sub
Private Sub cmdDelete_Click()
'delete record
'check existing selected record
If Not (Me.frmEquipmentListSub.Form.Recordset.EOF And Me.frmEquipmentListSub.Form.Recordset.BOF) Then
'confirm delete
If MsgBox("Are you sure you want to delete this piece of equipment?", vbYesNo) = vbYes Then
'delete now
CurrentDb.Execute "DELETE FROM tblEquipmentList " & _
"WHERE equipID =" & Me.frmEquipmentListSub.Form.Recordset.Fields("equipID")
'refresh data in list
Me.frmEquipmentListSub.Form.Requery
End If
End If
End Sub
Private Sub cmdEdit_Click()
'check whether there exists data in list
If Not (Me.frmEquipmentListSub.Form.Recordset.EOF And Me.frmEquipmentListSub.Form.Recordset.BOF) Then
'get data to text box control
With Me.frmEquipmentListSub.Form.Recordset
Me.txtID = .Fields("equipID")
Me.txtDesc = .Fields("equipDesc")
Me.txtManu = .Fields("equipManu")
Me.txtModelNum = .Fields("equipModelNum")
Me.txtSerNum = .Fields("equipSerNum")
Me.txtLastCalDate = .Fields("lastCalDate")
Me.txtCalDueDate = .Fields("calDue")
'store id of equipment in Tag of txtID in case id is modified
Me.txtID.Tag = .Fields("equipID")
'change caption of button add to Update
Me.cmdAdd.Caption = "Update"
'disable button edit
Me.cmdEdit.Enabled = False
End With
End If
End Sub
As you can see, I'm pretty confident that they're pretty much identical except for the field names.
I'm also linking an album of screenshots of the database here: http://imgur.com/a/xLV3Q
Thanks for any help you guys can provide.
The problem may be:
Your new table tblInventory has a column DESC which is a SQL reserved keyword. You have two options:
Drop the column DESC and create a new column with different name OR;
Add brackets to your script like this: INSERT INTO tblInventory([ICN], [manu], [model], [serial], [desc], [dateRec], [dateRem], [dispo], [project], [AMCA], [UL], [comments]).
Please check a full list of SQL reserved keywords: Reserved Keywords-Transact-SQL
I posted about this yesterday and have since made changes and attempted a few things to try and fix it and am still having trouble.
I'm working on a database for work and am getting a compile error when trying to add a record to a form.
It's essentially an inventory system, I have a table with the inventory of our warehouse and I'm trying to create a form that has a text box for every piece of information on a piece of equipment. So you go to the form, fill out each text box with the information and then there are 5 boxes to the side of the text boxes that you click to do different things. Below this there is a subform of the main inventory table.
There is an Add, Edit, Delete, Clear, and Close button. The Add button adds a record to this subform and consequently the main table with whatever information you type into the text boxes. To use the Edit box you click on a record in the subform and then click the Edit button and it will fill the text boxes with the information from the selected record, so that you can edit the information. At the same time, once you click Edit, it changes the label on the Add button to Update, so that once you have edited the data, you click Update and it will update the data in the subform and the main table. The other 3 buttons do what they're supposed to, you click a record and click delete to delete a record, click close to exit the form and click clear to clear any information that is filled in the text boxes.
The problem I'm having is that the Add/Update button isn't working - when I click it I get this error: Compile error: Method or data member not found. Every other button works perfectly fine and I have written and re written this code over twice now and can't figure out what's going on.
The weirdest part is that I basically copied this code over from another database that I coded that works exactly as intended and is super similar to this one. The only thing I even had to change when switching to this database was the names of the labels and table headers.
Can anyone help me out here?
Code:
Option Compare Database
Private Sub cmdAdd_Click()
'when we click on Add button there are two options
'1. for inserting new data
'2. for updating selected data
If Me.txtICN.Tag & "" = "" Then
'add data to table after clicking the add button
CurrentDb.Execute "INSERT INTO tblInventory(ICN, manu, modelNum, serialNum, descr, dateRec, projectNum, dispo, flgDispo, dateRemoved, comments, ulNum, amcaNum)" & _
"VALUES (" & Me.txtICN & ", '" & Me.txtManu & "', '" & Me.txtModel & "', '" & Me.txtSerial & "', '" & Me.txtDesc & "', '" & Me.txtDateRec & "', '" & Me.txtProjectNum & "','" & _
Me.txtDispo & "', '" & Me.chkDispo & "', '" & Me.txtDateRemoved & "', '" & Me.txtComments & "', '" & Me.txtULNum & "', '" & Me.txtAMCANum & "')"
Else
'otherwise
CurrentDb.Execute "UPDATE tblInventory " & _
" SET ICN =" & Me.txtICN & _
", manu ='" & Me.txtManu & "'" & _
", modelNum ='" & Me.txtModel & "'" & _
", serialNum ='" & Me.txtSerial & "'" & _
", descr ='" & Me.txtDescr & "'" & _
", dateRec ='" & Me.txtDateRec & "'" & _
", projectNum ='" & Me.txtProjectNum & "'" & _
", dispo ='" & Me.txtDispo & "'" & _
", flgDispo ='" & Me.chkDispo & "'" & _
", dateRemoved ='" & Me.txtDateRemoved & "'" & _
", comments ='" & Me.txtComments & "'" & _
", ulNum ='" & Me.txtULNum & "'" & _
", amcaNum ='" & Me.txtAMCANum & "'" & _
" WHERE ICN =" & Me.txtICN.Tag
End If
'clear form after data has been added to the table
cmdClear_Click
'refresh data in list on form after form has been cleared
frmInventorySub.Form.Requery
End Sub
Private Sub cmdClear_Click()
Me.txtICN = ""
Me.txtManu = ""
Me.txtModel = ""
Me.txtSerial = ""
Me.txtDesc = ""
Me.txtDateRec = ""
Me.txtProjectNum = ""
Me.txtDispo = ""
Me.chkDispo = ""
Me.txtDateRemoved = ""
Me.txtComments = ""
Me.txtULNum = ""
Me.txtAMCANum = ""
'set focus to ICN number
Me.txtICN.SetFocus
'set edit button to enabled after data has been cleared from form
Me.cmdEdit.Enabled = True
'change caption of button add to Add from Edit
Me.cmdAdd.Caption = "Add"
'clear tag on txtICN
Me.txtICN.Tag = ""
End Sub
Private Sub cmdClose_Click()
DoCmd.Close
End Sub
Private Sub cmdDelete_Click()
'delete record
'check existingselected record
If Not (Me.frmInventorySub.Form.Recordset.EOF And Me.frmInventorySub.Form.Recordset.BOF) Then
'confirm delete
If MsgBox("Are you sure you want to delete this record?)", vbYesNo) = vbYes Then
'delete now
CurrentDb.Execute "DELETE FROM tblInventory " & _
"WHERE ICN=" & Me.frmInventorySub.Form.Recordset.Fields("ICN")
'refresh data in list
Me.frmInventorySub.Form.Requery
End If
End If
End Sub
Private Sub cmdEdit_Click()
'check to see if data is already in the form
If Not (Me.frmInventorySub.Form.Recordset.EOF And Me.frmInventorySub.Form.Recordset.BOF) Then
'pull data from selected record into the text boxes
With Me.frmInventorySub.Form.Recordset
Me.txtICN = .Fields("ICN")
Me.txtManu = .Fields("manu")
Me.txtModel = .Fields("modelNum")
Me.txtSerial = .Fields("serialNum")
Me.txtDesc = .Fields("descr")
Me.txtDateRec = .Fields("dateRec")
Me.txtProjectNum = .Fields("projectNum")
Me.txtDispo = .Fields("dispo")
Me.chkDispo = .Fields("flgDispo")
Me.txtDateRemoved = .Fields("dateRemoved")
Me.txtComments = .Fields("comments")
Me.txtULNum = .Fields("ulNum")
Me.txtAMCANum = .Fields("amcaNum")
'store ICN in tag of txtICN in case ICN is modified
Me.txtICN.Tag = .Fields("ICN")
'change caption of add button to Update
Me.cmdAdd.Caption = "Update"
'disable edit button
Me.cmdEdit.Enabled = False
End With
End If
End Sub
Okay, I see it now. Your using the TAG property as an indicator if the record was edited or not. i.e. If it's a new record, then TAG = "", and if it's an existing record you replicate the ICN into the TAG.
If that's the case then change that IF statement to this:
If Me.txtICN.Tag = "" Then
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