Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to assign a date read from an Access table to a variable in Access 2003 using VBA code?

Posted on 2013-11-04
3
Medium Priority
?
658 Views
Last Modified: 2013-11-06
I am reposting this question because when I tried using the statement
dateFile = Left(Trim(bankname), 4) & " " & Format(Date, "mm/dd/yy")
I get the current date and not the date in the table.


I am developing an Access 2003 application using an MDB type file.

I have a table named  importMonthlyChecks from which I read a record and want to assign its date value in format MM/DD/YY to a variable field.

The first value for the field BankName which is a TEXT field with a length of 53 in the table importMonthlyChecks appears as follows:

Starting in position 5 is the value "DATE" and
Starting in postion 11 is the date value "10/31/13".

    DATE  10/31/13
--------------------------------------

I use the followng VBA code:

ssql = "select * from importMonthlyChecks where   Left(Trim(bankname), 4) = 'DATE' "
rst.Open ssql, con, 2, 2
dateFile = Left(Trim(bankname), 4) & " " & Format(Date, "mm/dd/yy")

However, instead of retrieving the value 10/31/13 in the variable dataFile,
I get the value of the current date in the variable dateFile?

Do you know how I can get the dateFile to be assigned the value "10/31/13" from the table
importMonthlyChecks?

-----------------

When I try:

 ssql = "select * from importMonthlyChecks where   Left(Trim(bankname), 4) = 'DATE' "
 rst.Open ssql, con, 2, 2
 dateFile = rst.Fields("bankname")

I get the value 12:00:00 AM for dateFile.
0
Comment
Question by:zimmer9
[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
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39622309
try this

dateFile =mid(rs!bankname, 5,4) & " " & mid(rs!bankname, 11,8)

or

dateFile =Left(Trim(rs!bankname), 4) & " " & mid(rs!bankname, 11,8)
0
 

Author Comment

by:zimmer9
ID: 39622445
It seems to me the problem lies with the first SQL statement:

ssql = "select * from importMonthlyChecks where   Left(Trim(bankname), 4) = 'DATE' "


rst.Open ssql, con, 2, 2
dateFile = rst.Fields("bankname")

because I get the value 12:00:00 AM for dateFile in the above sequence of statements.
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 39622461
for testing purposes, use this and see what we'll get

ssql = "select * from importMonthlyChecks"

rst.Open ssql, con, 2, 2

debug.print rs!bankname


so we can get the exact value from the field Bankname

or better upload a sample db with some records from the table..
0

Featured Post

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

670 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