473,395 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

vb6 ms.access database: Variable not defined

I have a database in ms.access,
I want to retrieve data in the database is based on today's date. I have a query like this.
but when I run this program, it is error.
'Variable not defined'

Expand|Select|Wrap|Line Numbers
  1. QuerySelect = "SELECT a.DN, b.DIN, c.PIN, c.UserName, b.Clock, d.ItemName " & _
  2.              "FROM ((ras_Device a INNER JOIN ras_AttRecord b ON a.DN=b.DN) " & _
  3.              "LEFT JOIN ras_Users c ON b.DIN=c.DIN) " & _
  4.              "LEFT JOIN ras_AttTypeItem d ON b.AttTypeId=d.ItemId " & _
  5.              "WHERE b.DIN=c.DIN AND '" & Format(b > *error,block area.Clock, "mm/dd/yyyy") & "'='" & _
  6.              Format(um_TglDanJamSkrg, "mm/dd/yyyy") & "'"
  7.  Set rsDataRAS = da_GetRs(QuerySelect)
Can anyone hel me to fix this error

Regards,
Octo
Oct 14 '10 #1
9 2242
MMcCarthy
14,534 Expert Mod 8TB
OK, firstly dates have to be enclosed with # marks rather than single quotes. So try this ..

Expand|Select|Wrap|Line Numbers
  1. QuerySelect = "SELECT a.DN, b.DIN, c.PIN, c.UserName, b.Clock, d.ItemName " & _
  2.              "FROM ((ras_Device a INNER JOIN ras_AttRecord b ON a.DN=b.DN) " & _
  3.              "LEFT JOIN ras_Users c ON b.DIN=c.DIN) " & _
  4.              "LEFT JOIN ras_AttTypeItem d ON b.AttTypeId=d.ItemId " & _
  5.              "WHERE b.DIN=c.DIN AND #" & Format(b > *error,block area.Clock, "mm/dd/yyyy") & "#=#" & _
  6.              Format(um_TglDanJamSkrg, "mm/dd/yyyy") & "#"
  7.  Set rsDataRAS = da_GetRs(QuerySelect)
  8.  
If that doesn't work then my guess is we need to look at these two values.

Expand|Select|Wrap|Line Numbers
  1. Format(b > *error,block area.Clock, "mm/dd/yyyy") 
and

Expand|Select|Wrap|Line Numbers
  1. Format(um_TglDanJamSkrg, "mm/dd/yyyy")
We'll need more information on where these values are coming from.

Mary
Oct 14 '10 #2
Dear Mary

thanks for the replies .. but it's still compile error: variable not defined and the same position on 'b.Clock at WHERE ..
#" & Format(b.Clock, "mm/dd/yyyy") & "#=#" & _
Format(um_TglDanJamSkrg, "mm/dd/yyyy") & "#"

Regards,
Octo
Oct 14 '10 #3
Expand|Select|Wrap|Line Numbers
  1. Format(b.Clock, "mm/dd/yyyy")
b.Clock from field in database ms.access table ras_AttRecord b field: Clock

Expand|Select|Wrap|Line Numbers
  1. Format(um_TgldanJamSkrg, "mm/dd/yyyy")
um_TgldanJamSkrg from definition of function
Expand|Select|Wrap|Line Numbers
  1. Public Function um_TgldanJamSkrg() As Date
  2. Dim rsJam As New Recordset
  3. Dim strSQL As String
  4.  
  5.     strSQL = "SELECT GETDATE() AS jam"
  6.     Set rsJam = da_GetRecord(strSQL)
  7.  
  8.     um_TgldanJamSkrg = rsJam!jam
  9.  
  10. rsJam.Close
  11. Set rsJam = Nothing
  12.  
  13. End Function
Oct 14 '10 #4
MMcCarthy
14,534 Expert Mod 8TB
You can't call a function just by inserting the function name in your code. Try this...

Expand|Select|Wrap|Line Numbers
  1. Dim tmpDate As Date
  2.  
  3.     tmpDate = um_TglDanJamSkrg()
  4.  
  5.     QuerySelect = "SELECT a.DN, b.DIN, c.PIN, c.UserName, b.Clock, d.ItemName " & _ 
  6.              "FROM ((ras_Device a INNER JOIN ras_AttRecord b ON a.DN=b.DN) " & _ 
  7.              "LEFT JOIN ras_Users c ON b.DIN=c.DIN) " & _ 
  8.              "LEFT JOIN ras_AttTypeItem d ON b.AttTypeId=d.ItemId " & _ 
  9.              "WHERE b.DIN=c.DIN AND Format(b.Clock, 'mm/dd/yyyy')=#" & _ 
  10.              Format(tmpDate, "mm/dd/yyyy") & "#" 
  11.     Set rsDataRAS = da_GetRs(QuerySelect) 
  12.  
Oct 14 '10 #5
Dear Mary,
Many Thanx, but now.. Run-time error
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
that caused the data is not available, right?

Regards,
Octo
Oct 14 '10 #6
MMcCarthy
14,534 Expert Mod 8TB
It sounds like either your function or your query is not returning any records.

Add Debug.Print QuerySelect just before the Set rsDataRAS = da_GetRs(QuerySelect) line. This will print out the query in the "Immediate" window. If you can't tell visually what the problem is then copy and paste the query into a new query and try running it.
Oct 14 '10 #7
Dear Mary,

I've added Debug.Print QuerySelect before Set rsDataRAS = da_GetRs(QuerySelect) line and then I copy and paste the query in the Form_Load, there is no issue, then the desired data are not artifacts in the database, right?

Regards,
Octo
Oct 14 '10 #8
MMcCarthy
14,534 Expert Mod 8TB
then I copy and paste the query in the Form_Load
I don't understand what you mean by this. I meant for you to create a new query in query design. Change the layout to sql and paste in the query. Then run it and see what the results are.

then the desired data are not artifacts in the database, right?
Not sure what you mean by this.
Oct 14 '10 #9
Dear Mary,

I have try & that's work, Thanks so much for your help..
GBU

Regards,
Octo
Oct 14 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Thomas Mlynarczyk | last post by:
Hello, Is there a way to access a static variable defined inside a function from outside that function? Something like the following: function foo() { static $bar = 'stuff'; // more code }
8
by: lkrubner | last post by:
An old friend of mine recently approached me and said something like: "I've a computer at my office that has an Access database running on it. We've most of our company info in there. We'd like to...
2
by: Atreju | last post by:
I apologize in advance for the x-post, but I am really not sure where this would best be addressed. I am designing a database in MSAccess for which I want to make the front-end in VB. I have...
5
by: kai | last post by:
Hi, All I try to block some one import my Access database tables using Access database. I used password protection, but if some one crack through my password, are there any other methods to...
7
by: carl.manaster | last post by:
I'm new to this game. I can find my way around C# without any trouble, and I've used Access, a little bit, in the past. Now a friend wants an application of mine to read from his Access database....
5
by: jeet_sen | last post by:
Hi, My external javascript test.js contains a variable definition var a = "Hello,world!!"; I dynamically loaded the script test.js using the following fucntion: function loadScript(url) { var...
2
by: Stephen E. Weber | last post by:
I have an access database with an "item number" and a filespec for a JPG with the image for the item and a filespec for a HTM document with the description and specifications. I use a List Box and...
4
by: bgreer5050 | last post by:
Where and how do I declare a variable that I want to use throughout the entire Access database? Thanks
4
by: =?Utf-8?B?ZG1idXNv?= | last post by:
I have an Access database with a table named 'tblMedia'. In tblMedia I have a field named 'Media' that is defined as an 'OLE Ojbect' field. In this Media field, I have pictures, they are jpegs. I'm...
6
by: Killer42 | last post by:
Hi all. I have an application that I wrote ages ago - last compiled in 1998, I believe. It is still in occasional use. It uses an Access database - probably Access version 2, I think. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.