7 Replies - 19891 Views - Last Post: 12 April 2009 - 04:21 AM Rate Topic: -----

#1 bobmarleypeople  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-April 09

Object variable or With block variable not set

Post icon  Posted 09 April 2009 - 04:12 PM

I'm currently writing a fairly basic part code generator with database connection for a company, and I'm having issues adding a new record on the Item side.

I've declared my variables as follows:

Dim Outlets As Integer	
Dim Sides As String	 
Dim Material As String  
Dim Brackets As String 
Dim Inlet As String	   
Dim Vent As String	   
Dim Outlet As String	   
Dim IOVcode As String
Dim ItemPrice As String



As well as the following in a module:

Global CODE As String
Global ItemPrice As Integer




The bit of code that doesn't want to work is the following:

Private Sub cmdDatabase_Click()

dataHeaders.Recordset.AddNew	 '<================= VB flags this up as the issue upon clicking debug

dataHeaders.Recordset![Outlets] = Outlets
dataHeaders.Recordset![Material] = Material
dataHeaders.Recordset![Sides] = Sides
dataHeaders.Recordset![Inlet] = Inlet
dataHeaders.Recordset![Outlet] = Outlet
dataHeaders.Recordset![Vent] = Vent
dataHeaders.Recordset![Brackets] = Brackets
dataHeaders.Recordset![Partcode] = CODE
dataHeaders.Recordset![Approximate Cost] = ItemPrice

dataHeaders.Recordset.Update

MsgBox "Data Saved Successfully", vbOKOnly, "Partcode"


cmdNew.Visible = True
cmdSend.Visible = True
cmdDatabase.Visible = False

End Sub



Upon clicking cmdDatabase, VB returns the error:


Visual Basic said:

Run-time error '91':

Object variable or With block variable not set.



When you click debug, as you can see in the code above, it highlights "dataHeaders.Recordset.AddNew" as the issue.


I hope you can help me as this error's got me tearing my hair out! I'll be more than happy to provide any additional information you require.

Regards, and thank you in advance,

--bobmarleypeople

Is This A Good Question/Topic? 0
  • +

Replies To: Object variable or With block variable not set

#2 Nikhil_07n  Icon User is offline

  • The cheese stands alone..
  • member icon

Reputation: 49
  • View blog
  • Posts: 2,489
  • Joined: 09-January 09

Re: Object variable or With block variable not set

Posted 09 April 2009 - 07:58 PM

whatever 'dataheaders' is.........you have'nt declared it/opened it.
Was This Post Helpful? 0
  • +
  • -

#3 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

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

Re: Object variable or With block variable not set

Posted 10 April 2009 - 01:16 AM

just a sugestion

set dataHeaders = New Adodb.Recordset




porbably you didnt seth the object
Was This Post Helpful? 0
  • +
  • -

#4 bobmarleypeople  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-April 09

Re: Object variable or With block variable not set

Posted 10 April 2009 - 03:50 AM

Thanks for the quick response.

dataheaders is the name of my ADODC control. Sorry I should have said that in my original post.

On adding the line of code NoBrain posted, VB gives the error "Object doesn't support this property or method."
Was This Post Helpful? 0
  • +
  • -

#5 GreaseMonkey  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 33
  • Joined: 23-March 09

Re: Object variable or With block variable not set

Posted 10 April 2009 - 04:19 AM

View Postbobmarleypeople, on 10 Apr, 2009 - 02:50 AM, said:

Thanks for the quick response.

dataheaders is the name of my ADODC control. Sorry I should have said that in my original post.

On adding the line of code NoBrain posted, VB gives the error "Object doesn't support this property or method."


if its anything like what i remember using in vba then you need to open the recordset first

dataHeaders.Recordset.Open
or
dataHeaders.Open

im not to sure on the syntax, but give that a try, it should work :)
Was This Post Helpful? 0
  • +
  • -

#6 bobmarleypeople  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-April 09

Re: Object variable or With block variable not set

Posted 11 April 2009 - 12:36 PM

View PostGreaseMonkey, on 10 Apr, 2009 - 03:19 AM, said:

if its anything like what i remember using in vba then you need to open the recordset first

dataHeaders.Recordset.Open
or
dataHeaders.Open

im not to sure on the syntax, but give that a try, it should work :)


Hmmm. On adding "dataHeaders.Recordset.Open" before the Addnew command, the same error occurs, but this time, the debug points to the .Open line instead.

This is really starting to confuse me now. From what I can tell, the code's right, but it's just not working.

Any other ideas?
Was This Post Helpful? 0
  • +
  • -

#8 Raju2047  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 55
  • Joined: 16-February 09

Re: Object variable or With block variable not set

Posted 12 April 2009 - 01:53 AM

have u define the recordset,connection string in adodc properties.
if then just
no need to do open the recordset
just before your code add
dataheaders.refresh  ' add this code
dataheaders.recordset.addnew


Was This Post Helpful? 1

#9 bobmarleypeople  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-April 09

Re: Object variable or With block variable not set

Posted 12 April 2009 - 04:21 AM

View PostRaju2047, on 12 Apr, 2009 - 12:53 AM, said:

have u define the recordset,connection string in adodc properties.
if then just
no need to do open the recordset
just before your code add
dataheaders.refresh  ' add this code
dataheaders.recordset.addnew




IT WORKS! IT BLOODY WORKS!!! (why didn't I think of that >_<)

Thank you so much for your help!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1