The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
Form Issue
Posted: 18 Jan 08 12:39 PM
|
On the Account Details form I have added the following code to the FormOpen event. The message box's come up and show the correct Data, but the fields on the form never enable. What am I doing wrong?
Sub AXFormOpen(Sender) Dim strSQL Dim strQ Dim strC Dim oShell Dim tUserID
tUserID = application.basicfunctions.CurrentUserID
Set rs = CreateObject("ADODB.Recordset") With rs Set .ActiveConnection = Application.GetNewConnection .CursorLocation = adUseClient .CursorType = adOpenStatic .LockType = adLockOptimistic .Open "select * from UserInfo where userID = '" & tUserID & "'" MsgBox .Fields("UserID").Value MsgBox .Fields("Title").Value
IF .Fields("UserID").Value = "ADMIN" or .Fields("Title").Value = "Director of Marketing" or .Fields("Title") = "Sales Admin" then
tbxEmployeesThisLocation.Enabled = true tbxEmployeeTotal.Enabled = true plGrade.Enabled = true plOwnership.Enabled = true tbxRevenue.Enabled = true
tbxEmployeesThisLocation.ReadOnly = false tbxEmployeeTotal.ReadOnly = false plGrade.ReadOnly = false plOwnership.ReadOnly = false tbxRevenue.ReadOnly = false End IF
.Close End With Set rs = Nothing End Sub |
|
|
|
Re: Form Issue
Posted: 18 Jan 08 4:37 PM
|
What fields are these bound to? If you created the fields against the base account table (and even if you didn't you should check) check field security profiles in the SalesLogix Administrator and make sure they are enabled for the read/write default profile.
I've found that when adding fields to the base tables that the field level security defaults to 'no access' for those.
also you are only specifying .Fields("Title") and not .Fields("Title").Value in your if statement.
|
|
|
|
Re: Form Issue
Posted: 18 Jan 08 4:47 PM
|
The IF statement is likely short-circuiting. Group the IF conditions in parens like this:
IF (.Fields("UserID").Value = "ADMIN") or (.Fields("Title").Value = "Director of Marketing") or (.Fields("Title") = "Sales Admin") then
It also might be a good idea to trim those values as well, it won't pass this check if there are spaces at the end. Also, your code will error if someone has a NULL title value. You can treat NULL values as blank strings by appending a blank string to it (instead of .Fields("title").Value use .Fields("title").Value & "", make sense?)
-Ryan |
|
|
|
Re: Form Issue
Posted: 18 Jan 08 4:55 PM
|
I created seperate Tables for Employees and Ownership and used the existing Revenue field from the account Table. They are all set to read / write. Ive changed it to .value and it still doesnt work. I am getting error:
Multiple-Step Operation Generated errors. Check each status Value.
Here is the code being called, I am not sure why its giving me an error. before I tried to change the read-only value of the fields it would allow me to change them just fine and record the change to the database. Now it errors or wont even remove the read only flag.
Sub tbxRevenueExitControl(Sender) Dim strSQL Dim strQ Dim strC Dim oShell Dim tUserID Dim tAccountID Dim tCreateUser Dim tModifyUser
tUserID = application.basicfunctions.CurrentUserID tAccountID = frmAccountDetail.CurrentID tCreateUser = application.basicfunctions.CurrentUserID tModifyUser = application.basicfunctions.CurrentUserID
Set rs = CreateObject("ADODB.Recordset") With rs Set .ActiveConnection = Application.GetNewConnection .CursorLocation = adUseClient .CursorType = adOpenStatic .LockType = adLockOptimistic .Open "select * from ACCOUNT where ACCOUNTID = '" & tAccountID & "'"
'If .RecordCount = 0 Then ' .AddNew ' .Fields("ACCOUNTID").Value = tAccountID ' .Fields("CREATEUSER").Value = tUserID ' .Fields("CREATEDATE").Value = Now
' End If
.Fields("MODIFYUSER").Value = tUserID .Fields("MODIFYDATE").Value = Now .Fields("REVENUE").Value = tbxRevenue.Text .Update .Close End With Set rs = Nothing End Sub
Sub plOwnerShipExitControl(Sender) Dim strSQL Dim strQ Dim strC Dim oShell Dim tUserID Dim tAccountID Dim tCreateUser Dim tModifyUser
tUserID = application.basicfunctions.CurrentUserID tAccountID = frmAccountDetail.CurrentID tCreateUser = application.basicfunctions.CurrentUserID tModifyUser = application.basicfunctions.CurrentUserID
Set rs = CreateObject("ADODB.Recordset") With rs Set .ActiveConnection = Application.GetNewConnection .CursorLocation = adUseClient .CursorType = adOpenStatic .LockType = adLockOptimistic .Open "select * from OWNERSHIP where ACCOUNTID = '" & tAccountID & "'"
If .RecordCount = 0 Then .AddNew .Fields("ACCOUNTID").Value = tAccountID .Fields("CREATEUSER").Value = tUserID .Fields("CREATEDATE").Value = Now
End If
.Fields("MODIFYUSER").Value = tUserID .Fields("MODIFYDATE").Value = Now .Fields("OWNERSHIPTYPE").Value = plOwnership.Text .Update .Close End With Set rs = Nothing End Sub
Sub tbxEmployeeTotalExitControl(Sender) Dim strSQL Dim strQ Dim strC Dim oShell Dim tUserID Dim tAccountID Dim tCreateUser Dim tModifyUser
tUserID = application.basicfunctions.CurrentUserID tAccountID = frmAccountDetail.CurrentID tCreateUser = application.basicfunctions.CurrentUserID tModifyUser = application.basicfunctions.CurrentUserID
Set rs = CreateObject("ADODB.Recordset") With rs Set .ActiveConnection = Application.GetNewConnection .CursorLocation = adUseClient .CursorType = adOpenStatic .LockType = adLockOptimistic .Open "select * from EMPLOYEE where ACCOUNTID = '" & tAccountID & "'"
If .RecordCount = 0 Then .AddNew .Fields("ACCOUNTID").Value = tAccountID .Fields("CREATEUSER").Value = tUserID .Fields("CREATEDATE").Value = Now
End If
.Fields("MODIFYUSER").Value = tUserID .Fields("MODIFYDATE").Value = Now .Fields("EMPLOYEETOTAL").Value = tbxEmployeeTotal.Text .Update .Close End With Set rs = Nothing End Sub
Sub tbxEmployeesThisLocationExitControl(Sender) Dim strSQL Dim strQ Dim strC Dim oShell Dim tUserID Dim tAccountID Dim tCreateUser Dim tModifyUser
tUserID = application.basicfunctions.CurrentUserID tAccountID = frmAccountDetail.CurrentID tCreateUser = application.basicfunctions.CurrentUserID tModifyUser = application.basicfunctions.CurrentUserID
Set rs = CreateObject("ADODB.Recordset") With rs Set .ActiveConnection = Application.GetNewConnection .CursorLocation = adUseClient .CursorType = adOpenStatic .LockType = adLockOptimistic .Open "select * from EMPLOYEE where ACCOUNTID = '" & tAccountID & "'"
If .RecordCount = 0 Then .AddNew .Fields("ACCOUNTID").Value = tAccountID .Fields("CREATEUSER").Value = tCreateUser .Fields("CREATEDATE").Value = Now
End If
.Fields("MODIFYUSER").Value = tModifyUser .Fields("MODIFYDATE").Value = Now .Fields("EMPLOYEESTHISLOCATION").Value = tbxEmployeesThisLocation.Text
.Update .Close End With Set rs = Nothing End Sub
Sub AXFormOpen(Sender) Dim strSQL Dim strQ Dim strC Dim oShell Dim tUserID
tUserID = application.basicfunctions.CurrentUserID
Set rs = CreateObject("ADODB.Recordset") With rs Set .ActiveConnection = Application.GetNewConnection .CursorLocation = adUseClient .CursorType = adOpenStatic .LockType = adLockOptimistic .Open "select * from UserInfo where userID = '" & tUserID & "'" MsgBox .Fields("UserID").Value MsgBox .Fields("Title").Value
IF .Fields("UserID").Value = "ADMIN" or .Fields("Title").Value = "Director of Marketing" or .Fields("Title").Value = "Sales Admin" then
tbxEmployeesThisLocation.ReadOnly = false tbxEmployeeTotal.ReadOnly = false plGrade.ReadOnly = false plOwnership.ReadOnly = false tbxRevenue.ReadOnly = false End IF
.Close End With Set rs = Nothing End Sub
|
|
|
|
Re: Form Issue
Posted: 18 Jan 08 4:59 PM
|
Here's a question, is there a better approach for what I am trying to do? |
|
|
|
Re: Form Issue
Posted: 18 Jan 08 5:13 PM
|
Originally posted by NebSeb
Here's a question, is there a better approach for what I am trying to do? |
|
Yes 
Your problem is that (guessing here) your controls are bound to fields in the database but you're also trying to write the values to the fields in the database at the same time (on the exit event), so the data has been changed already when the bindings attempt to save.
Are the controls bound to fields in the database or not?
-Ryan
|
|
|
|
Re: Form Issue
Posted: 18 Jan 08 5:22 PM
|
Yes they are bound to fields in the database. |
|
|
|
Re: Form Issue
Posted: 18 Jan 08 5:29 PM
|
The funny thing is that if i am not trying to set the txtboxes to read only or not read only, it workds fine, there is no problem with writing the data and i dont get an error. Only when i try to determine if someone should be able to edit the value of the field do i get the error. |
|
|
|
Re: Form Issue
Posted: 18 Jan 08 8:28 PM
|
We should probably start back at square one. What's the goal here NebSeb? I'm not real sure why you would bind the data to the database AND attempt to write it to the database as well that is not necessary. What are you trying to do? Just make it so only certain people can edit a value on your form?
|
|
|
|
Re: Form Issue
Posted: 18 Jan 08 10:19 PM
|
Originally posted by NebSeb
Yes they are bound to fields in the database. |
|
Then you don't need the code to manually write them to the database. All you need to do is control whether they are enabled or not - all the other code can go (the updates on the exit event of the controls). Keep the code you've added in the form open and scrap the rest.
-Ryan |
|
|
|
Re: Form Issue
Posted: 19 Jan 08 7:44 AM
|
Just as an aside in vb6 and vbscript there is not short circuting in conditionals. This was a short coming in the language and it existed in the c-derived languages. Short circuiting did not come to vb until 1.0 of vb.net when the vb language team added the OrElse and the AndAlso keywords. These new keywords offer the short circuting. IIF also suffers from this as it will resolve all parts in the conditon (condition, RHS, LHS) will be run so if the condition is true both the right hand value and left hand will be resolved.
Mark |
|
|
|
Re: Form Issue
Posted: 19 Jan 08 7:49 AM
|
it looks from your code that your also setting a few fields. if you need to set them, since the rest of the form is bound why not just put on hidden controls and assign the values to the control and use all of the form binding code to handle your insert/updates. I also believe that the create/modify stuff is now handled by the provided so you more then likely do not need to assign these values at all.
|
|
|
|