Enable / disable menu items using session in vb.net - vb.net

If Session IsNot Nothing And Session("Admin") = "ftghgy" Then
Dim rptMenuItem As MenuItem = Menu1.FindItem("Home")
rptMenuItem.Selectable = True
Label9.Text = ("Welcome")
Else
Label9.Text = ("Welcome " + "" + Session("UserName").ToString)
endif
I am getting this error...
"Object reference not set to an instance of an object" on this line "rptMenuItem.Selectable = True"
I and am not using a master page.

Well, then probably this line is returning null value :
Menu1.FindItem("Home")
Meaning that an item with id "Home" couldn't be found in your Menu1.

I think it must be integer Menu1.FindItem(Type)

Related

Access vba filter button

I am trying to make a form with two filter buttons.
First button will + 1 to the filter and
second button will -1 to the filter.
so far I have.
Dim ADD As String
If Me.TypeID Is Empty Then
'empty TypeID, do nothing
Else
ADD = Me.TypeID + 1
DoCmd.ApplyFilter "", "[TypeID] = " & ADD
End If
I am getting
error 2427
because I can't trap if the next TypeID doesn't exist.
For example, I have now 4 records as TypeId. If I add 1, I will have 5 which I don't have.
Thank you.
Find it.
Dim Add As String
Dim LastID As Integer
LastID = DMax("TypeID", "tblType")
If Me.TypeID = LastID Then
'Empty TypeID, Do Nothing...
Else
Add = Me.TypeID + 1
DoCmd.ApplyFilter "", "[TypeID] = " & Add
End If
Do not forget to set:
Me.filter on = true

.FilterOn Method Not Working

K Access guru's. I have a module that requery's a main form, then set's a filter based on a value in a field, and requery's the subforms with that filter. The problem is when I set subform.FilterOn = True, it doesnt do anything and returns False. I'd rather not upload the whole solution. But heres a screenshot of the code with the highlighted part showing the discrepancy. Below is the code for copy/paste purposes. Why is this not working?
Private Sub Combo7_AfterUpdate()
Dim strSQL As String
Application.Echo False
strSQL = "[APN] = " & Str(Nz(Me![Combo7], 0))
DoCmd.ApplyFilter wherecondition:=strSQL
Me![Combo22].Requery
Me![Combo22] = Me![Text24]
Dim val As String
Dim subform1 As Form
Dim subform2 As Form
Dim subform3 As Form
val = Me![Text24]
Set subform1 = Me.qPayment_subform.Form
Set subform2 = Me.qRefundWriteOff_subform.Form
Set subform3 = Me.qRetnCHK_subform.Form
subform1.FilterOnLoad = True
subform2.FilterOnLoad = True
subform3.FilterOnLoad = True
subform1.FilterOn = True
subform2.FilterOn = True
subform3.FilterOn = True
subform1.Filter = "PeriodID = " & val
subform2.Filter = "PeriodID = " & val
subform3.Filter = "PeriodID = " & val
subform1.Requery
subform2.Requery
subform3.Requery
Application.Echo True
End Sub
Give subform container control a name different from the object it holds. For instance, if the form is named frmOrderDetails name the container ctrDetails. Then maybe using the container name in setting the object variables will work. If not, consider eliminating the variables and just referencing the container name.
With Me
...
.ctrDetails.Form.FilterOn = True
...
End With
I know this means repeating .Form but it will be fast edit.
In any case, set the Filter property before FilterOn.
Also, FilterOnLoad and Requery are not necessary.

ListView : Fetch data from selected item

I have created a listview and populated it using datatable..
All worked fine... Now I added checkbox to all items..
Now I want like when the last column's value of an item is "true" then the checkbox of the same item is checked.
I tried the following code...
If LstViewHelp.Items.Count <> 0 Then
For Each item As ListViewItem In LstViewHelp.Items
If LstViewHelp.FocusedItem.SubItems(10).Text = "True" Then
LstViewHelp.FocusedItem.Checked = True
End If
Next
End If
I am getting the following error object reference is not set to an instance.
Tried many links but no proper solution found...!
You can get all selected index like ListView.SelectedIndexCollection using SelectedIndices . Add ForEach loop on selected indexes and edit your SubItem.
Dim indexes As ListView.SelectedIndexCollection = Me.ListViewHelp.SelectedIndices
For Each index In indexes
If Me.ListViewHelp.Items(index).SubItems(10).Text = "True" Then
LstViewHelp.Items(index).Checked = True
End If
Next
And if you want to check all items you can use for loop
For i = 0 To Me.ListViewHelp.Items.Count - 1
If Me.ListViewHelp.Items(i).SubItems(10).Text = "True" Then
LstViewHelp.Items(i).Checked = True
End If
Next

Evaluate("1") gives error 438

I have few "Why?"s about evaluate...
Sub TestEvaluate()
Dim Tag As String
Tag = "5"
Tag = Evaluate(Tag) 'works fine
Tag = "1"
Tag = Evaluate(Tag) 'error 438 wrong property or method(-> my 1st "Why?")
But ok i can handle it:
Tag = "1"
Tag = [Tag] 'works fine
Now I need to evaluate a property of some object:
Dim Object As cObject
Set Object = New cObject
Object.pProperty = "5"
Tag = Evaluate(Object.pProperty) 'Works fine
And again the same problem as above:
Object.pProperty = "1"
Tag = Evaluate(Object.pProperty) '438 wrong property or method
But now i'm traped, becouse:
Tag = [Object.pProperty] 'generates error 13 type mismatch(-> my 2nds "Why?")
Is there some solution without the need to use a new variable?
Dim TempTag As String
TempTag = Object.pProperty
Tag = [TempTag] 'everything fine again
End Sub
i found out, in my case VBA.Evaluate("1") generates an object according to
debug.print VBA.VarType(evauate("1"))
It`s just a bug? (win8.1 xl2007)
I put the expression into brackets and the problem disappeared; works fine now:
Tag = Evaluate("(" & Tag & ")")
This is better solution for me:
Tag = Evaluate(Tag & "+0")
It is a solution for the Error 2015 when the Tag="" as well.

Weird strange things happening in repository record!

SubSonic 2.2. I use the repository record pattern, with a table "appointment" with an appointmentId as auto-incrementing int.
I am trying to update it, but when I do update the fields with something totally different, dirty columns are always zero, and I get an exception.
System.NullReferenceException: Object reference not set to an instance of an object. at SubSonic.DataService.ExecuteQuery(QueryCommand cmd) at SubSonic.SubSonicRepository.Update[T](RepositoryRecord1 item, String userName) at janji.Janji.Data.DB.Update[T](RepositoryRecord1 item) in A:\Source\VS2008\Web\Apps\janji\janji\Classes\DAL\AllStructs.vb:line 197 at janji.WebForm4.SaveData() in A:\Source\VS2008\Web\Apps\janji\janji\UI\Appt.aspx.vb:line 343
Here's my code:
Try
If Appointment.AppointmentId > 0 Then
Appointment.AddressName = uxHotel.Text
Appointment.Address = uxAddress.Text
Appointment.AppStartTime = Date.Parse(uxApptDate.SelectedDate.Value.ToShortDateString + " " + uxApptStartTime.SelectedDate.Value.ToShortTimeString)
Appointment.ApptEndTime = Date.Parse(uxApptDate.SelectedDate.Value.ToShortDateString + " " + uxApptEndTime.SelectedDate.Value.ToShortTimeString)
Appointment.Completed = uxCOmpleted.Checked
Appointment.DropNumber = uxDropNum.Text
Appointment.Total = 0
Appointment.EmployeeId = 0
Appointment.Model = uxModel.Text
Appointment.DropAmount = Decimal.Parse(uxDropAmount.SelectedValue)
Appointment.RoomNumber = uxRoom.Text
'If Appointment.DirtyColumns.Count > 0 Then
Janji.Data.DB.Update(Of Janji.Data.Appointment)(Appointment)
'End If
End If
Catch ex As Exception
_ErrorMessage = ex.ToString
RetVal = False
lErrors.Text = _ErrorMessage
lErrors.Visible = True
End Try
You're using the Structs we provide instead of instantiating an Appointment object. Do everything you're doing here, but create an Appointment instance and assign it the values. Then pass that instance to the repo.