how to query full name with null values in MS Access? - ms-access

This is my code in ms access in giving the full name with null values
lname for last name
fname for first name
mname for middle name (change into initial)
x for name extensions like Jr., Sr., III ect.
this is the code.
[lname] & ", " & [fname] & " " & IIf(IsNull([x]),"",([x]) & ", ") & " " & IIf(IsNull(Left([mname],1)),"",(Left([mname],1)) & ".")
but when i try it to mysql it does not give any data. anyone is free to edit or reconstruct my code to fit the qualifications in mysql query. SALAMAT, MABUHAY

Related

How to write code IN VB6 SHAPE coding from 3 tables FOR DATA REPORT group heading

nstring = "SHAPE {SELECT PRODUCTID,PRODUCTNAME FROM PRODUCTMASTER } " & _
" APPEND ((SHAPE {SELECT * FROM ORDERDETAILS WHERE ORDERNO='" &
"10001" & "' }" & _
" APPEND ({SELECT PRODUCTID,ITEMCODE,ITEMNAME FROM ITEMDETAILS }
AS ORDITEMS RELATE " & _
" PRODUCTID TO PRODUCTID,ITEMCODE TO ITEMCODE)) AS ORDERS RELATE
PRODUCTID TO PRODUCTID)"
The above code in "VB6 MS ACCESS DATABASE (ACCDB) for data report . Group Header (Section 6) = Productname
Details (Section 1 ) for all other fields including Itemname
But "itemname" showing error in Data report Section 1 as
"Data Field orders.itemname not found "
Why does this occur?

Insert a value into a table while creating a record in another table

I'm out of my league on this... Another developer before me did something similar to what I want to do by adding a value in a table while updating another table. However, he was running updates as well as inserting, and his primary key was text. Mine PK is integer. Here's his code (works great) that I am trying to reverse engineer and apply to my situation:
Dim sqlQuery As String
sqlQuery = "IF EXISTS (SELECT ReportPK FROM
ACIST_MobilePipelineReportReviewed WHERE ReportPK = '" & ReportPk & "') " &
_
" UPDATE ACIST_MobilePipelineReportReviewed set Status = 'Approved'
WHERE ReportPK = '" & ReportPk & "'" & _
" ELSE " & _
" INSERT INTO ACIST_MobilePipelineReportReviewed ([ReportPK],
[PipelineUID],[ReportDate],[ReportInspector],[Status]) VALUES (" & _
"'" & ReportPk & "','" & Me!PipelineUID & "','" & Me!ReportDate & "','"
& Me!ReportInspector & "','Approved')"
End Sub
Here's what I'm doing: I have a combo box on a form called FacilityEntryF. That form is tied to my FacilityT table. I am selecting "CampaignID" from the CampaignT table and adding it to the FacilityT using that combo box in the aforementioned form. No biggie there... Works great.
The FacilityT has many columns of which I have [FacilityID] which is the primary key and is an autogenerated integer. It also has a column for [CampaignID] which is a foreign key from the CampaignT table.
After adding the CampaignID and starting a new FacilityID in FacilityT, I also want to create a new record in my CampaignFacilityParticipationT table. That table consists of only three columns: CampaignFacilityParticipationID, CampaignID, ParticipantFacilityID. I want to take the new [FacilityID] and the [CampaignID] I added to that table and insert them into the CampaignFacilityParticipationT table (FacilityID goes into the ParticipantFacilityID column). Here's the code below that didn't work (which I'm not surprised because I don't know what I'm doing):
Dim sqlQuery As String
sqlQuery = "IF EXISTS (SELECT FacilityID FROM FacilityT WHERE FacilityID =
" & FacilityID) " & _
" INSERT INTO CampaignFacilityParticipationT ([CampaignFacilityParticipationID],[CampaignID],[ParticipantFacilityID]) VALUES (" & _
"" & CampaignFacilityParticipationID,'" & Me!CampaignID," & Me!ParticipantFacilityID, CampaignID)"
End Sub
Using MS Access 2013 with Microsoft SQL backend.
Thanks!!!
Concatenation is not correct. If apostrophes are needed to delimit parameters then make sure they are used consistently. Normally in Access, apostrophes would only be used for text fields, # for date/time and nothing for number. Maybe because backend is MS SQL apostrophes are needed for all field types? Why do you repeat CampaignID in VALUES clause?
sqlQuery = "IF EXISTS (SELECT FacilityID FROM FacilityT WHERE FacilityID = '" & Me!FacilityID & "')" & _
" INSERT INTO CampaignFacilityParticipationT ([CampaignFacilityParticipationID],[CampaignID],[ParticipantFacilityID])" & _
" VALUES ('" & Me!CampaignFacilityParticipationID & "','" & Me!CampaignID & "','" & Me!ParticipantFacilityID & "')"
Is it possible for you to use a subform on FacilityEntryF on which you select the CampaignID? That will eliminate the need for this code.

Runtime Error 3134 - Syntax Error in INSERT INTO Statement

I'm trying to fix it about hour but it's not work Please help me :(
CurrentDb.Execute "INSERT INTO match_day( home_team, away_team, date, time, home_score, away_score, stadium) " & _
" VALUES('" & Me.textHT & "','" & Me.textAT & "',#" & Me.textDATE & "#,#" & Me.textTime & "#," & Me.textHS & "," & Me.textAS & ",'" & Me.textSTD & ",')"
Are the fields for date and time considered reserved words and should be wrapped in brackets or ticks to qualify it as the column name...
..., [date], [time], ...
But I think it is most likely the trailing final comma before your final closing ) of the inserted values making it look like it wants another field to be inserted.
Me.textSTD & ",')"
change to
Me.textSTD & "')"
I ran into a similar error - thanks to this post I realised that I had used a reserved name "note" in a table ( instead of "notes").
StrSQL = "INSERT INTO option_notes ( OPTION_ID , USER_ID , [NOTE] ) VALUES ( " & currID & " , " & currUserID & " , '" & currNote & "' ) ; "
CurrentDb.Execute StrSQL
I ended up changing the field name - however, wrapping the field name with [ ] allowed the code to execute correctly.

How do I manage to hide my ID field in my form

So I have a form and a combo box that was made by the SQL code
SELECT [EmployeeID] & " " & [FirstName] & " " & [LastName] AS Employees
FROM Employees;
I use this to make a combo box but I want to hide the EmployeeID field from the combo box and not by removing EmployeeID from the SQL statement.
My current combo box is
Employee ID + " " + FirstName + " " + LastName
how do I change it to
FirstName + " " + LastName?
Help? D:
That's not how you bind to a combobox.
If you want the combobox to only show the FirstName and LastName together, then the bound query for the RowSource of the combobox:
SELECT [EmployeeID],
[FirstName] & " " & [LastName] AS EmployeeName
FROM Employees;
Then configure the combobox as follow:
And set the first column width to 0 to hide it:

How to combine mutiple column with comma separator?

I have 11 columns as Note1,Note2,Note3,......Note11. I have write a query like this to combine
SELECT DormData.BuildingID,
DormData.DormRoomID,
DormData.Item,
DormData.Result,
DormData.InspectorID,
DormData.Date,
DormData.Qty,
DormData.Section,
(Note1 & " , "
& Note2 & ", "
& Note3 & " , "
& Note4 & " , "
& Note5 & " , "
& Note6 & " , "
& Note7 & ", "
& Note8 & ", "
& Note9 & ", "
& Note10 & ", "
& Note11) AS Notes,
DormData.Comments,
DormData.Resident
FROM DormData;
It works and combine my records but problem is that it is not necessary that all the notes
columns have values.suppose that if in a row there is values in only Note1 and Note5 then it gives output like not1,,,,note5. but I want it show "Note1,Note5"
How can I fix this?
You could use an Iif statement in each 'Note1 * ","' section to check for null values.
Iif(IsNull(Note1), Note1, Note1 & ",")
I think that should work.
The key is IIF() aka immediate if.
For example, on the orders table in the Northwind sample database:
IIF(orders.ShipRegion IS NOT NULL, orders.ShipRegion & ',', ''
Or a more complete query:
SELECT
orders.OrderID, orders.CustomerID, orders.EmployeeID,
orders.ShipVia, orders.Freight,
(orders.ShipName & ',' & orders.ShipCity & ',' & IIF(orders.ShipRegion IS NOT NULL, orders.ShipRegion & ',', '') & orders.ShipPostalCode & ',' & orders.ShipCountry) AS Expr1
FROM orders
WHERE orders.[OrderID]=10282;
If you want to go the vba function route, the following function will do the job:
Function JoinStrings(Delimiter As String, _
ParamArray StringsToJoin() As Variant) As String
Dim v As Variant
For Each v In StringsToJoin
If Not IsNull(v) Then
If Len(JoinStrings) = 0 Then
JoinStrings = v
Else
JoinStrings = JoinStrings & Delimiter & v
End If
End If
Next v
End Function
You would call it like this:
JoinStrings(", ", Note1, Note2, Note3, Note4, Note5, Note6, Note7)
You can also use a trick with how Null expressions and concatenation works in Access:
Note1 & (", " + Note2) & (", " + Note3)...
When concatenating text, Access treats Null as it were an empty string. But if you're "adding", the Null would cause the expression inside the parentheses to result in Null. As long as your notes aren't numeric, this will work.
A modification to TheOtherTimDuncan' solution, which will work well to concatenate two (or may be three) Notes. Use IIF() to have delimiter or blank based on whether Note1 is Null. It could be like:
Note1 & (IIF(Note1 Is Null, "",", ") + Note2) & (IIF((Note1 & Note2) Is Null, "",", ") + Note3)...