Solved

setting a variable to Data field contents

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

746 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

15 Experts available now in Live!

Get 1:1 Help Now