Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

setting a variable to Data field contents

Posted on 1998-07-15
3
Medium Priority
?
204 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 200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

610 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