Records Don't Update (1 Viewer)

FoxSettle

Registered User.
Local time
Today, 03:23
Joined
Aug 7, 2019
Messages
11
I have a linked DB with view's and tables. Naturally I can't edit anything with in a view since i'm using inner and left joins but I have it set up that I can change the Tables and here's where the problem occurs. In general I'm creating a Help Desk system for my employer and I have to add new Faults that we come across daily. I am using pre-made database with only the tables and columns we use.

So logically I will have to be able to add new faults and have them displayed. To display my faults on my "MainPage"<-(Form) I use a view from my SSMS(SQL Server Managment Studio) dbo_VwMainFaults<-(View) and to add a new fault I insert it in to a linked Table dbo_Faults<-(Table).
My dbo_VwMainFaults uses dbo_faults and few other tables like user and Area
Now my problem is that after adding a new fault in to my Faults Table I can't see it in my MainPage, The new data is for sure being inserted in to my Faults Table but my View doesn't re-query/update.
I know that my Faults Table is updated because if I change the record source in my mainpage to that table the new records show as intended but they don't appear if Record Source is set to the view table. :banghead:


My VBA Code to add new Ticket:
Code:
Private Sub btnSaveFault_Click()

Dim rs As Recordset
Dim db As Database

Set db = CurrentDb
Set rs = db.OpenRecordset("dbo_Faults")

rs.AddNew
rs.Fields("FaultGUID") = Left(Me.nFaultid.Value, 38)
rs.Fields("hdid") = Me.txthdid.Value
rs.Fields("username") = Me.Username.Value
rs.Fields("phonenumber") = Me.phonenumber.Value
rs.Fields("Symptom") = Me.Symptom.Value
rs.Fields("symptom2") = Me.symptom2.Value
rs.Fields("category2") = Me.category2.Value
rs.Fields("category3") = Me.category3.Value
rs.Fields("takenby") = Me.takenby.Value
rs.Fields("MessSent") = Me.MessSent.Value
rs.Fields("RequestTypeNew") = Me.RequestTypeNew.Value
rs.Fields("urgency") = Me.urgency.Value
rs.Fields("causedby") = Me.causedby.Value
rs.Fields("Status") = Me.Status.Value
rs.Fields("datereported") = Me.datereported.Value
rs.Fields("dateoccured") = Me.dateoccured.Value
rs.Fields("seriousness") = Me.seriousness.Value
rs.Fields("Areaint") = Me.Areaint.Value
rs.Fields("sitenumber") = Me.sitenumber.Value
rs.Fields("estimate") = Me.estimate.Value
rs.Fields("datecreated") = Me.datecreated.Value
rs.Fields("datecleared") = Me.datecleared.Value
rs.Fields("cleartime") = Me.cleartime.Value
rs.Fields("fixbydate") = Me.fixbydate.Value
rs.Fields("clearance") = Me.clearance.Value

Dim DAOErr As DAO.Error

Debug.Print "Error raised: " & Err.Number

For Each DAOErr In DBEngine.Errors
    Debug.Print DAOErr.Number, DAOErr.Description, DAOErr.Source
Next DAOErr

rs.Update
MsgBox "New Ticket was Added"




rs.Close
Set rs = Nothing
db.Close
'Forms("HomePage").Form.SetFocus ' , , "FaultGUID = " & Me.nFaultid & ""
 DoCmd.Close , NewTicket, acSaveYes
 DoCmd.OpenForm "HomePage", acNormal
'Set rs = Forms("HomePage").Form.Recordset
'rs.FindFirst "FaultGUID = '" & Me.nFaultid & "'"

End Sub

This is how I am updating/altering my Faults Table.
also I had a issue with ODBC linking my access front end to my DB so I had that error displaying code in place to explain why its causing it but I didn't fix it it just fixed it self after leaving it for the night.

My FaultGUID is a GUID to generate a random ID< That GUID was placed there by me and replaced the original PK faultID which was a integer. I've only replaced it because it saves me worrying about a ticket being added by two people at the same time and having the same ID... but anyway I some how feel like my PK FaultGUID is not linking my Table[dbo_faults] properly with the View [dbo_VwMainFaults]

My SQL code to create the view I need:
Code:
Create VIEW [dbo].[VwMainFaults]
AS
Select 
		f.Symptom,
		f.symptom2,
		f.takenby,
		s.sdesc,
		s.Ssitenum,
		f.username,
		f.phonenumber,
		f.sectio_,
		f.sitenumber,
		f.cleartime,
		f.datecreated,
		f.hdid,
		f.estimate,
		f.datereported,
		f.causedby,
		f.clearance,
		f.Areaint,
		f.category2,
		f.category3,
		f.datecleared,
		f.Slaid,
		f.Slareason,
		f.Slastate,
		f.MessSent,
		f.MessSentLast,
		f.urgency,
		f.Requesttype,
		f.RequestTypeNew,
		f.Approvedby,
		f.Status,
		f.seriousness,
		f.dateoccured,
		ar.aareadesc,
		f.FaultGUID
		
From dbo.Site S
Inner Join  dbo.Faults f 
ON f.sitenumber = s.Ssitenum
Inner Join dbo.Area Ar ON f.Areaint = ar.Aarea


GO


I feel like this SQL statement is missing something that just doesn't update it with the new Faults table. How could I work around it or make it to work and display new tickets as I added them. :confused:
 

FoxSettle

Registered User.
Local time
Today, 03:23
Joined
Aug 7, 2019
Messages
11
So come to think of it all I need is the View to just requery after new ticket is added or requery on load

I have this in place but it doesn't work, will try it under ON Load Event but don't think it will help
Code:
Private Sub Form_Activate()
Me.Requery

End Sub

I feel like I will need to include some SQL in my VB code for it to UPDATE my View
 
Last edited:

NauticalGent

Ignore List Poster Boy
Local time
Today, 06:23
Joined
Apr 27, 2015
Messages
6,321
So come to think of it all I need is the View to just requery after new ticket is added or requery on load

I have this in place but it doesn't work, will try it under ON Load Event but don't think it will help
Code:
Private Sub Form_Activate()
Me.Requery

End Sub
I feel like I will need to include some SQL in my VB code for it to UPDATE my View

Greetings and welcome to AWF!
I am not too proficient with SQL so I am afraid I cannot help you with personal experience. That being said, I have read about the issue with Views not automatically updating.
Give this a read, it appears you can write a procedure and then execute a pass-thru query to refresh the table.
https://www.mssqltips.com/sqlserver...automatically-reflected-in-a-sql-server-view/

Best of luck and please report back on how you get this sorted...
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:23
Joined
Oct 29, 2018
Messages
21,454
Hi. Welcome to the forum. Does the new record show up if you close and reopen the form with the view? Just curious...
 

isladogs

MVP / VIP
Local time
Today, 11:23
Joined
Jan 14, 2017
Messages
18,209
NG's suggestion should work.
For info, the Activate event isn't always triggered on a form but Load event always is.
Are you suggesting closing and reloading the form after each record is created?

Rather than use a view which is read only, could you use a form/subform arrangement each based on one table?

I suggest you revert to using an auto number long integer field for your PK field. Two users should not be able to cause a clash. GUIDs seem to cause no end of problems which could be avoided.
 

FoxSettle

Registered User.
Local time
Today, 03:23
Joined
Aug 7, 2019
Messages
11
Thank you everyone for replying.

To be perfectly honest I don't really need that view to display the information Its just nice because I can use filter by Sites and Clients but if I use my Faults Table I wont see that information but there are other ways about it was just convenient to use that view

NauticalGent thank you for the link, I have only attempted to use the SP_Refreshview and with in my SSMS it doesn't change anything which is alarming and I haven't tried the Drop/Create or Alter methods just yet.

TheDBguy No the records stay as they were since I created the View.

Isladogs yes I probably will be better off trying to make it work with subforms to display the site location and company name.
The GUID was recommended to me by a coworker and he has a lot more experience than me.
 

FoxSettle

Registered User.
Local time
Today, 03:23
Joined
Aug 7, 2019
Messages
11
and yes I close the Main form while my Addnew form is opened and reopen it once I close Addnew
 

FoxSettle

Registered User.
Local time
Today, 03:23
Joined
Aug 7, 2019
Messages
11
I've found something weird.

So I've attempted to Drop the View and recreate it hoping that what ever i've added to my faults will display in SSMS but to my surprise after creating the view from beginning I'm still not seeing any new records and I have a slight feeling that it has something to do with the Left Join in my sql code. Anyone got a clue why when I drop the view I'm still not seeing updated records??
:banghead::banghead::banghead::banghead::banghead::banghead:
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:23
Joined
Oct 29, 2018
Messages
21,454
I've found something weird.

So I've attempted to Drop the View and recreate it hoping that what ever i've added to my faults will display in SSMS but to my surprise after creating the view from beginning I'm still not seeing any new records and I have a slight feeling that it has something to do with the Left Join in my sql code. Anyone got a clue why when I drop the view I'm still not seeing updated records??
:banghead::banghead::banghead::banghead::banghead::banghead:
Hi. I'm not sure what you mean. In the SQL code you posted for the VIEW, I don't see a LEFT JOIN, it's all INNER JOINs.
 

FoxSettle

Registered User.
Local time
Today, 03:23
Joined
Aug 7, 2019
Messages
11
Sorry you are right I was thinking of a different view that I was trying to get to work earlier. my bad

in that case I have no idea why my view doesn't include new records after being created from scratch.

I even tried making a view that is using FROM dbo.Faults Table and still same results
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:23
Joined
Feb 19, 2002
Messages
43,223
1. Views are normally updateable.
2. To make a view not updateable, you need to join to a table that the user cannot update or include aggregation or a table that has no primary key. There may be other reasons but I update views all the time. The updateablility of a view has nothing to do with whether it uses inner or outer joins or some combination of the two. Cross joins are not updateable by certain RDBMS'
3. The "Access way" is to bind forms to tables/queries/views and let Access perform the update. When you do it yourself, you are accepting all the bad stuff that Access brings but not taking advantage of the good stuff. Access is a Rapid Application Development (RAD) tool. To use it effectively, you should go with the flow rather than rolling your own (in a few years, no one will know what that actually means).
4. If the requery doesn't work, perhaps there is some criteria in the query that is preventing the new record from being selected.
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 06:23
Joined
Apr 27, 2015
Messages
6,321
4. If the requery doesn't work, perhaps there is some criteria in the query that is preventing the new record from being selected.

That would be my quess, although the OP seems to know what he/she is doing...
 

FoxSettle

Registered User.
Local time
Today, 03:23
Joined
Aug 7, 2019
Messages
11
Just to note the view's I use were originally queries in Access and everything worked once I moved them to Managment Studio if all went down hill from there.

I just don't understand how my Faults Table updates normally yet the view from that table doesn't.

I might have some Primary Keys missing from one of the tables

Anyway thanks for the replies and if this whole thing fails I'll remake my whole Database just to be sure everything is there.
 

FoxSettle

Registered User.
Local time
Today, 03:23
Joined
Aug 7, 2019
Messages
11
So I've solved it and it was as simple as pressing few buttons....

Sooo my sql code for my view looks like this now

Code:
CREATE VIEW [dbo].[VwMainFaultsWorking]
AS
SELECT        f.Symptom, f.symptom2, f.takenby, S.sdesc, S.Ssitenum, f.username, f.phonenumber, f.sectio_, f.sitenumber, f.cleartime, f.datecreated, f.hdid, f.estimate, f.datereported, f.causedby, f.clearance, f.Areaint, f.category2, f.category3, 
                         f.datecleared, f.Slaid, f.Slareason, f.Slastate, f.MessSent, f.MessSentLast, f.urgency, f.Requesttype, f.RequestTypeNew, f.Approvedby, f.Status, f.seriousness, f.dateoccured, Ar.aareadesc, f.FaultGUID
FROM            dbo.Faults AS f [COLOR="Blue"]LEFT OUTER JOIN[/COLOR]
                         dbo.Area AS Ar ON f.Areaint = Ar.Aarea [COLOR="blue"]LEFT OUTER JOIN[/COLOR]
                         dbo.Site AS S ON f.sitenumber = S.Ssitenum

So my views were 1 to 1 and they had to include all of my Faults not just the ones that are linked by area id ect.

Simply went in to view properties and changed the relationships to include all from Faults and it works.
 

FoxSettle

Registered User.
Local time
Today, 03:23
Joined
Aug 7, 2019
Messages
11
I need to make 3 more posts to post a picture of where I changed it
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:23
Joined
Oct 29, 2018
Messages
21,454
Hi. Congratulations! Glad to hear you got it sorted out. Good luck with your project.
 
Last edited:

NauticalGent

Ignore List Poster Boy
Local time
Today, 06:23
Joined
Apr 27, 2015
Messages
6,321
Glad you got it working, and again, welcome to AWF
 

isladogs

MVP / VIP
Local time
Today, 11:23
Joined
Jan 14, 2017
Messages
18,209
@FoxSettle
Congratulations on solving your problem

1. Views are normally updateable.
2. To make a view not updateable, you need to join to a table that the user cannot update or include aggregation or a table that has no primary key. There may be other reasons but I update views all the time. The updateablility of a view has nothing to do with whether it uses inner or outer joins or some combination of the two. Cross joins are not updateable by certain RDBMS

@Pat
I have a different perspective on this.
1. If a view is read only in SSMS, it will definitely be read only in Access.
2. If updateable in SSMS, it may be editable in Access providing a primary key is assigned to the view in Access. This can easily be done during setup using ODBC connections.
However I always use DSN-less connections which have many advantages. One disadvantage is you cannot create a PK when linking to a view. That makes it read only.
It is possible to add a PK using code subsequently but this will need renewing if you need to relink at a later date
 

Users who are viewing this thread

Top Bottom