Solved

setting a variable to Data field contents

Posted on 1998-07-15
3
200 Views
Last Modified: 2008-03-06
I have declared my Variables as string and need to set each variable to the contents of a database field.  I set the variables like this:

Dim coststat1 As String
Dim coststat2 As String
Dim coststat3 As String
Dim coststat4 As String
Dim Schedstat1 As String
Dim Schedstat2 As String
Dim Schedstat3 As String
Dim Schedstat4 As String
Dim Perfstat1 As String
Dim Perfstat2 As String
Dim Perfstat3 As String
Dim Perfstat4 As String
Dim antCoststat As String
Dim antSchedstat As String
Dim antPerfstat As String

Then I try to set the variable to the current content of a database field with the following:
coststat1 = frmProgram.Data1.Recordset.Fields("coststat_1")
    coststat2 = frmProgram.Data1.Recordset.Fields("coststat_2")
    coststat3 = frmProgram.Data1.Recordset.Fields("coststat_3")
    coststat4 = frmProgram.Data1.Recordset.Fields("coststat_4")
    Schedstat1 = frmProgram.Data1.Recordset.Fields("schedstat_1")
    Schedstat2 = frmProgram.Data1.Recordset.Fields("schedstat_2")
    Schedstat3 = frmProgram.Data1.Recordset.Fields("schedstat_3")
    Schedstat4 = frmProgram.Data1.Recordset.Fields("schedstat_4")
    Perfstat1 = frmProgram.Data1.Recordset.Fields("perfstat_1")
    Perfstat2 = frmProgram.Data1.Recordset.Fields("perfstat_2")
    Perfstat3 = frmProgram.Data1.Recordset.Fields("perfstat_3")
    Perfstat4 = frmprogram.data1.Recordset.Fields("perfstat_4")


I get an error "Object variable or With Block Varible not set"

What am I doing wrong?????
0
Comment
Question by:clarwc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Accepted Solution

by:
biko071598 earned 50 total points
ID: 1465828
The error "Object variable or With Block Varible not set" should read "I'm trying to access an object that doesn't exist!"

It looks like you are trying to get cheap data access by using a data control instead of opening a database object and opening a recordset object.  If this is the case, your data control's recordset object is not initialized. Possible reasons are: no/incorrect database specified, no/incorrect recordsource property specified. Set these properties in the form load event and make sure the form loads before you access the data.  

You can cut down on the typing by using an alternate syntax.

Use:
"coststat2 = frmProgram.Data1.Recordset!coststat_2"

Instead of:
"coststat2 = frmProgram.Data1.Recordset.Fields("coststat_2")
"

Good luck
0
 

Author Comment

by:clarwc
ID: 1465829
bike,

I tried your suggestion and got the same message.  I don't care so much about saving code as I do having the function work correctly.  I have the statements in my Form_load event.  do I need to open the database first?  

I tried :

Dim mydb as database
Dim myrs as recordset

Set mydb = workspaces(1).opendatabase("c:\205gui\205 data.mdb")
Set myrs = mydb.openrecordset("programs", dbopentable)


But it doesn't work....

Any other ideas?????
0
 

Expert Comment

by:biko071598
ID: 1465830
>>Set mydb = workspaces(1).opendatabase("c:\205gui\205 data.mdb")
Could it be that the filename is inccorrect (i.e. embedded space?)

try this...

Dim mydb as database
Dim myrs as recordset

Set mydb = opendatabase("c:\205gui\somedata.mdb") <--"Make sure path if fine..use 8.3 file notation like in msdos...)
 
Set myrs = mydb.openrecordset("programs", dbopendynaset) <--- use a dynaset of you can
 
set data1.recordset = myrs

mind that you must have the professional edition of vb4 or vb5 to do this.  What version are you using?

You can also try this instead...
If you simply want to verify the datacontrol, pull up the form and set the database and recordsource properties.  Then put at least one dataaware control on the form and point it to the datacontrol.  Test the form by showing it verifying that you have data.  Then try the routine....

Good Luck



0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question