Solved

setting a variable to Data field contents

Posted on 1998-07-15
3
195 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 / DAO 3.6 / run time error: Couldn't find installable ISAM 7 71
MsgBox 2 47
Excel - Save a copy of work book 13 82
VBA filters 2 49
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

939 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now