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
648 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

695 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