vb error "object variable or with block variable not set"

im trying to retrieve data from ms sql 2008 database

Page 1 of 1

2 Replies - 3397 Views - Last Post: 19 August 2009 - 12:27 AM Rate Topic: -----

#1 clovers25  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 23-October 07

vb error "object variable or with block variable not set"

Posted 18 August 2009 - 07:36 PM

sorry, but im quite new in vb, i hope you can help me out.

i get an error of "object variable or with block variable not set"


Private Sub Form_Load()
Sn.Text = ""
Pw.Text = ""

End Sub
Private Sub Command1_Click()


db.Recordset.Filter = "[StudNum] LIKE %" + Sn.Text + "%"	   'error comes here

	If (Len(Sn.Text) < 8) And (IsNumeric(Sn.Text)) Then
	babala = MsgBox("Student Number Should Contain 8 Numbers.", vbInformation + vbOKOnly, "Information")
	ElseIf (Len(Sn.Text) > 8) And (IsNumeric(Sn.Text)) Then
	babala = MsgBox("Student Number Should Only Contain 8 Numbers.", vbInformation + vbOKOnly, "Information")
	ElseIf Not IsNumeric(Sn.Text) Then
	babala = MsgBox("Student Number Should Only Contain Numbers.", vbInformation + vbOKOnly, "Information")
	Else
	Unload Me
	MainPage.Show
	End If
End Sub


This post has been edited by clovers25: 18 August 2009 - 07:49 PM


Is This A Good Question/Topic? 0
  • +

Replies To: vb error "object variable or with block variable not set"

#2 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: vb error "object variable or with block variable not set"

Posted 18 August 2009 - 11:27 PM

so on what line you got the error i think it is db.Recordset.Filter if so where do you declare it. is that ADODB.RecordSet if so you need to do one of this

Dim db As New ADODB.RecordSet



if you dont use word "New" in your declaration you must seth it later like so:

Dim db As ADODB.RercordSet 
Set db = New ADODB.RecordSet




tel mi if it works :)
good luck :)
Was This Post Helpful? 0
  • +
  • -

#3 clovers25  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 23-October 07

Re: vb error "object variable or with block variable not set"

Posted 19 August 2009 - 12:27 AM

thank you NoBrain dunno why you chose that name but it really helped me.

thanks again.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1