"Error 91 object variable or with block variable not set"
this error appears on the search command found in form2 here is the whole code:
Sub searchingthelist()
[color="#FFA500"]If Not rs.EOF Then[/color] <<<<< [color="#FF0000"]This is where its making an error[/color]
ListView1.ListItems.Clear
rs.MoveFirst
Do While Not rs.EOF
Set Item = ListView1.ListItems.Add(, , rs!LastName)
Item.SubItems(1) = rs!FirstName
Item.SubItems(2) = rs!Company
Item.SubItems(3) = rs!StreetAddress
Item.SubItems(4) = rs!City
Item.SubItems(5) = rs!Region
Item.SubItems(6) = rs!ZipCode
Item.SubItems(7) = rs!HomePhone
Item.SubItems(8) = rs!WorkPlace
rs.MoveNext
Loop
Else
ListView1.ListItems.Clear
End If
rs.Close
Set rs = Nothing
End Sub
Sub search()
If comb.Text = "LastName" Then
Set rs = New ADODB.Recordset
rs.Open "select * from table_save where LastName like '" & txtSearch.Text & "%';", cn, adOpenKeyset, adLockOptimistic
Form2.searchingthelist
ElseIf comb.Text = "FirstName" Then
Set rs = New ADODB.Recordset
rs.Open "select * from table_save where Firstname Like '" & txtSearch.Text & "%';", cn, adOpenKeyset, adLockOptimistic
Form2.searchingthelist
End If
End Sub
Private Sub Additional_Click()
Frame5.Width = 6015
Frame5.Height = 2295
End Sub
Private Sub asa_Click()
On Error Resume Next
Set rs = New ADODB.Recordset
rs.Open "select * from Room_no", ae, adOpenKeyset, adLockOptimistic
rs!Roomno = RN3.Text
rs!Deluxe = z.Text
rs!ExtraBed = x.Text
rs!ExtraPerson = k.Text
rs.Close
Set rs = Nothing
Form2.List_records3
End Sub
Private Sub C_Click()
On Error Resume Next
If C = "Lovely(2)" Then AP.Text = "1500"
If C = "Sweetie(4)" Then AP.Text = "2250"
If C = "Honey(6)" Then AP.Text = "3000"
If C = "Lovely(2)" Then total.Text = 1500 * NOD.Text
If C = "Sweetie(4)" Then total.Text = 2250 * NOD.Text
If C = "Honey(6)" Then total.Text = 3000 * NOD.Text
End Sub
Private Sub C1_Click()
If C1.Text = "Food" Then
Form2.C2.AddItem "Cake"
Form2.C2.AddItem "etc."
Else
Form2.C2.AddItem "Television"
Form2.C2.AddItem "Radio"
End If
End Sub
Private Sub C2_Click()
If C2.Text = "Cake" Then A.Text = 250
If C2.Text = "etc." Then A.Text = "350"
If C2.Text = "Television" Then A.Text = "500"
If C2.Text = "Radio" Then A.Text = "150"
End Sub
Private Sub Check15_Click()
If Check15.Value = 1 Then
NOP.Enabled = True
Else
NOP.Enabled = False
NOP.Text = ""
End If
End Sub
Private Sub Check2_Click()
If Check2.Value = 1 Then
z.Text = "980"
Else
z.Text = ""
End If
End Sub
Private Sub Check3_Click()
If Check3.Value = 1 Then
b.Text = 250
v.Visible = True
Else
v.Text = ""
v.Visible = False
End If
End Sub
Private Sub Check4_Click()
If Check4.Value = 1 Then
j.Text = 250
NOP.Visible = True
Else
NOP.Text = ""
NOP.Visible = False
End If
End Sub
Private Sub Clear_Click()
BI.Text = ""
BD.Text = ""
LN.Text = ""
FN.Text = ""
CI2.Text = ""
CO.Text = ""
RN2.Text = ""
C.Text = ""
NOD.Text = ""
NOP.Text = ""
AP.Text = ""
total.Text = ""
End Sub
Private Sub cmdDelete_Click()
On Error Resume Next
Set rs = New ADODB.Recordset
rs.Open "select * from table_save where LastName='" + Trim(txtLN.Text) + " '", cn, adOpenKeyset, adLockPessimistic
rs.Clone
msg1 = MsgBox("Are you sure you want to delete this?", vbokcanel, "delete")
If msg1 = vbOK Then
rs.Delete
Set rs = Nothing
MsgBox "Deleted!"
Form2.List_records
txtLN.Text = ""
txtFN.Text = ""
txtComp.Text = ""
txtSA.Text = ""
txtCity.Text = ""
cmbR.Text = ""
txtZC.Text = ""
txtHP.Text = ""
txtWP.Text = ""
End If
End Sub
Private Sub cmdSave1_Click()
On Error Resume Next
Set rs = New ADODB.Recordset
rs.Open "select * from table_save", cn, adOpenKeyset, adLockOptimistic
rs.AddNew
rs!LastName = txtLN.Text
rs!FirstName = txtFN.Text
rs!Company = txtComp.Text
rs!StreetAddress = txtSA.Text
rs!City = txtCity.Text
rs!Region = cmbR.Text
rs!ZipCode = txtZC.Text
rs!HomePhone = txtHP.Text
rs!WorkPlace = txtWP.Text
rs.Update
MsgBox "Saved"
rs.Close
Set rs = Nothing
Form2.List_records
txtLN.Text = ""
txtFN.Text = ""
txtComp.Text = ""
txtSA.Text = ""
txtCity.Text = ""
cmbR.Text = ""
txtZC.Text = ""
txtHP.Text = ""
txtWP.Text = ""
txtLN.Enabled = False
txtFN.Enabled = False
txtComp.Enabled = False
txtSA.Enabled = False
txtCity.Enabled = False
cmbR.Enabled = False
txtZC.Enabled = False
txtHP.Enabled = False
txtWP.Enabled = False
cmdSave1.Enabled = False
cmdDelete.Enabled = False
cmdUpdate.Enabled = False
End Sub
Sub List_records()
Set rs = New ADODB.Recordset
rs.Open " select *from table_save", cn, adOpenKeyset, adLockOptimistic
If Not rs.EOF Then
ListView1.ListItems.Clear
rs.MoveFirst
Do While Not rs.EOF
Set Item = ListView1.ListItems.Add(, , rs!LastName)
Item.SubItems(1) = rs!FirstName
Item.SubItems(2) = rs!Company
Item.SubItems(3) = rs!StreetAddress
Item.SubItems(4) = rs!City
Item.SubItems(5) = rs!Region
Item.SubItems(6) = rs!ZipCode
Item.SubItems(7) = rs!HomePhone
Item.SubItems(8) = rs!WorkPlace
rs.MoveNext
Loop
Else
ListView1.ListItems.Clear
End If
rs.Close
Set rs = Nothing
End Sub
Sub List_records2()
On Error Resume Next
Set rs = New ADODB.Recordset
rs.Open " select *from Guest_ID", ar, adOpenKeyset, adLockOptimistic
If Not rs.EOF Then
ListView2.ListItems.Clear
rs.MoveFirst
Do While Not rs.EOF
Set Item = ListView2.ListItems.Add(, , rs!BookingID)
Item.SubItems(1) = rs!BookingDate
Item.SubItems(2) = rs!GuestName
Item.SubItems(3) = rs!Name
Item.SubItems(4) = rs!CheckIn
Item.SubItems(5) = rs!CheckOut
Item.SubItems(6) = rs!RoomNumber
Item.SubItems(7) = rs!RateType
Item.SubItems(8) = rs!NumberOfDays
Item.SubItems(9) = rs!NumberOfPersons
Item.SubItems(10) = rs!Paid
rs.MoveNext
Loop
Else
ListView2.ListItems.Clear
End If
rs.Close
Set rs = Nothing
End Sub
Private Sub cmdSearch_Click()
Form3.Show vbModal
Frame3.Height = 6615
Frame3.Width = 6015
End Sub
Private Sub cmdUpdate_Click()
Set rs = New ADODB.Recordset
rs.Open "select * from table_save where LastName='" + Trim(txtLN.Text) + " '", cn, adOpenKeyset, adLockPessimistic
rs!LastName = txtLN.Text
rs!FirstName = txtFN.Text
rs!Company = txtComp.Text
rs!StreetAddress = txtSA.Text
rs!City = txtCity.Text
rs!Region = cmbR.Text
rs!ZipCode = txtZC.Text
rs!HomePhone = txtHP.Text
rs!WorkPlace = txtWP.Text
rs.Update
rs.Close
Set rs = Nothing
Form2.List_records
End Sub
Private Sub Combo2_Change()
If "single" = 1000 Then Text11.Text = 1000
End Sub
Private Sub comb_Change()
If comb.Text = "Name" Then
Set rs = New ADODB.Recordset
rs.Open "select * from table_save where LastName like '" & txtSearch.Text & "%';", cn, adOpenKeyset, adLockOptimistic
Form2.searchingthelisthelist
End If
End Sub
Private Sub Command1_Click()
txtLN.Text = ""
txtFN.Text = ""
txtComp.Text = ""
txtSA.Text = ""
txtCity.Text = ""
cmbR.Text = ""
txtZC.Text = ""
txtHP.Text = ""
txtWP.Text = ""
txtLN.Enabled = True
txtFN.Enabled = True
txtComp.Enabled = True
txtSA.Enabled = True
txtCity.Enabled = True
cmbR.Enabled = True
txtZC.Enabled = True
txtHP.Enabled = True
txtWP.Enabled = True
cmdSave1.Enabled = True
cmdDelete.Enabled = True
cmdUpdate.Enabled = True
End Sub
Private Sub DTPicker1_Click()
Text1.Text = DTpic
End Sub
Private Sub Command3_Click()
On Error Resume Next
Set rs = New ADODB.Recordset
rs.Open "select * from Guest_ID", ar, adOpenKeyset, adLockOptimistic
rs.AddNew
rs!BookingID = BI.Text
rs!BookingDate = BD.Text
rs!GuestName = LN.Text
rs!Name = FN.Text
rs!CheckIn = CI2.Text
rs!CheckOut = CO.Text
rs!RoomNumber = RN2.Text
rs!RateType = C.Text
rs!NumberOfDays = NOD.Text
rs!NumberOfPersons = NOP.Text
rs!Paid = AP.Text
rs.Update
MsgBox "Saved"
rs.Close
Set rs = Nothing
Form2.List_records2
End Sub
Private Sub Command4_Click()
On Error Resume Next
Set rs = New ADODB.Recordset
rs.Open "select * from Guest_ID where BookingDate='" + Trim(BD.Text) + " '", ar, adOpenKeyset, adLockPessimistic
rs.Delete
msg1 = MsgBox("Are you sure you want to delete this?", vbokcanel, "delete")
If msg1 = vbOK Then
rs.Delete
Set rs = Nothing
MsgBox "Deleted!"
Form2.List_records2
BI.Text = ""
BD.Text = ""
LN.Text = ""
CI2.Text = ""
CO.Text = ""
RN2.Text = ""
C.Text = ""
NOD.Text = ""
NOP.Text = ""
AP.Text = ""
End If
End Sub
Private Sub Command5_Click()
On Error Resume Next
Set rs = New ADODB.Recordset
rs.Open "select * from Guest_ID where BookingDate='" + Trim(BD.Text) + " '", ar, adOpenKeyset, adLockPessimistic
rs!BookingID = BI.Text
rs!BookingDate = BD.Text
rs!GuestName = LN.Text
rs!Name = FN.Text
rs!CheckIn = CI2.Text
rs!CheckOut = CO.Text
rs!RoomNumber = RN2.Text
rs!RateType = C.Text
rs!NumberOfDays = NOD.Text
rs!NumberOfPersons = NOP.Text
rs!Paid = AP.Text
rs.Update
rs.Close
Set rs = Nothing
Form2.List_records2
End Sub
Private Sub Command6_Click()
On Error Resume Next
Set rs = New ADODB.Recordset
rs.Open "select * from Guest_ID", ar, adOpenKeyset, adLockOptimistic
rs!BookingID = BI.Text
rs!BookingDate = BD.Text
rs!GuestName = LN.Text
rs!Name = FN.Text
rs!CheckIn = CI2.Text
rs!CheckOut = CO.Text
rs!RoomNumber = RN2.Text
rs!RateType = C.Text
rs!NumberOfDays = NOD.Text
rs!NumberOfPersons = NOP.Text
rs!Paid = AP.Text
rs.Update
rs.Close
Set rs = Nothing
Form2.List_records2
End Sub
Private Sub Command7_Click()
On Error Resume Next
total.Text = Val(AP.Text * NOD.Text) + Val(NOP.Text * 250)
End Sub
Private Sub Command8_Click()
NOP.Text = 1 + 1
End Sub
Private Sub D_Click()
CO.Text = D.Value
End Sub
Private Sub DB_Change()
NOD.Text = DB.Text
End Sub
Private Sub Done_Click()
Frame5.Width = 0
Frame5.Height = 0
End Sub
Private Sub DT_Click()
CD.Text = DT.Value
BD.Text = DT.Value
CI2.Text = DT.Value
End Sub
Private Sub Form_Load()
txtLN.Enabled = False
txtFN.Enabled = False
txtComp.Enabled = False
txtSA.Enabled = False
txtCity.Enabled = False
cmbR.Enabled = False
txtZC.Enabled = False
txtHP.Enabled = False
txtWP.Enabled = False
cmdSave1.Enabled = False
cmdDelete.Enabled = False
cmdUpdate.Enabled = False
cmbR.AddItem "NCR"
cmbR.AddItem "CAR"
cmbR.AddItem "Region I"
cmbR.AddItem "Region II"
cmbR.AddItem "Region III"
cmbR.AddItem "Region IVA"
cmbR.AddItem "Region IVB"
cmbR.AddItem "Region V"
cmbR.AddItem "Region VI"
cmbR.AddItem "Region VII"
cmbR.AddItem "Region VIII"
cmbR.AddItem "Region X"
cmbR.AddItem "Region XI"
cmbR.AddItem "Region XII"
cmbR.AddItem "Region ARMM"
Form2.List_records
Form2.List_records2
Form2.List_records3
C.AddItem "Lovely(2)"
C.AddItem "Sweetie(4)"
C.AddItem "Honey(6)"
comb.Clear
comb.AddItem "LastName"
comb.AddItem "FirstName"
Form2.searchingthelist
Set rs = New ADODB.Recordset
rs.Open "select * from table_save", cn, adOpenKeyset, adLockOptimistic
Form2.Show vbModal
End Sub
Private Sub k_Change()
A.Text = Val(z.Text) + Val(x.Text) + Val(k.Text)
End Sub
Private Sub l_Change()
k.Text = Val(l.Text) * Val(j.Text)
End Sub
Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
With Item
txtLN.Text = .Text
txtFN.Text = .SubItems(1)
txtComp.Text = .SubItems(2)
txtSA.Text = .SubItems(3)
txtCity.Text = .SubItems(4)
cmbR.Text = .SubItems(5)
txtZC.Text = .SubItems(6)
txtHP.Text = .SubItems(7)
txtWP.Text = .SubItems(8)
FN.Text = .SubItems(1)
LN.Text = .Text
End With
End Sub
Private Sub Text10_Change()
Text11.Text = Val(Text10.Text) * Val(Text11.Text)
End Sub
Private Sub Text11_Change()
On Error Resume Next
End Sub
Private Sub Text2_Change()
Text10.Text = Text2.Text
End Sub
Private Sub Text3_Change()
Text9.Text = Text3.Text
End Sub
Private Sub ListView2_ItemClick(ByVal Item As MSComctlLib.ListItem)
With Item
BI.Text = .Text
BD.Text = .SubItems(1)
LN.Text = .SubItems(2)
FN.Text = .SubItems(3)
CI2.Text = .SubItems(4)
CO.Text = .SubItems(5)
RN2.Text = .SubItems(6)
C.Text = .SubItems(7)
NOD.Text = .SubItems(8)
NOP.Text = .SubItems(9)
AP.Text = .SubItems(10)
End With
End Sub
Private Sub NOD_Change1()
On Error Resume Next
: If C = "Lovely(2)" Then total.Text = (AP.Text * 1500)
: If C = "Sweetie(4)" Then AP.Text = (2250 * NOD.Text)
: If C = "Honey(6)" Then AP.Text = (3000 * NOD.Text)
End Sub
Private Sub NOD_Change2()
If NOD.Text = NOD.Text Then
total.Text = NOD.Text * AP.Text
End If
End Sub
Private Sub ListView3_ItemCheck(ByVal Item As MSComctlLib.ListItem)
With Item
RN3.Text = .Text
z.Text = .SubItems(1)
v.Text = .SubItems(2)
NOP.Text = .SubItems(3)
A.Text = .SubItems(4)
End With
End Sub
Private Sub NOD_Change()
total.Text = Val(AP.Text) * Val(NOD.Text)
End Sub
Private Sub NOP_Change()
k.Text = Val(NOP.Text) * Val(j.Text)
End Sub
Private Sub RN_Change()
RN2.Text = RN.Text
End Sub
Private Sub RN2_Change()
RN3.Text = RN2.Text
End Sub
Private Sub SV_Click()
On Error Resume Next
Set rs = New ADODB.Recordset
rs.Open "select * from Table_record", ae, adOpenKeyset, adLockOptimistic
rs.AddNew
rs!Roomno = RN3.Text
rs!Deluxe = z.Text
rs!ExtraBed = v.Text
rs!ExtraPerson = NOP.Text
rs!Additionals = A.Text
rs.Update
MsgBox "Saved"
rs.Close
Set rs = Nothing
Form2.List_records3
End Sub
Sub List_records3()
On Error Resume Next
Set rs = New ADODB.Recordset
rs.Open " select *from Table_record", ae, adOpenKeyset, adLockOptimistic
If Not rs.EOF Then
ListView3.ListItems.Clear
rs.MoveFirst
Do While Not rs.EOF
Set Item = ListView3.ListItems.Add(, , rs!Roomno)
Item.SubItems(1) = rs!Deluxe
Item.SubItems(2) = rs!ExtraBed
Item.SubItems(3) = rs!ExtraPerson
Item.SubItems(4) = rs!Additionals
rs.MoveNext
Loop
Else
ListView3.ListItems.Clear
End If
rs.Close
Set rs = Nothing
End Sub
Private Sub Text1_Change()
Form2.search
End Sub
Private Sub txtSearch_Change()
Form2.search
End Sub
Private Sub v_Change()
x.Text = Val(v.Text) * Val(b.Text)
End Sub
Private Sub x_Change()
A.Text = Val(z.Text) + Val(x.Text) + Val(k.Text)
End Sub
Private Sub z_Change()
A.Text = Val(z.Text) + Val(x.Text) + Val(k.Text)
End Sub
This post has been edited by BobRodes: 26 March 2012 - 02:55 PM

New Topic/Question
Reply



MultiQuote




|