Quick VB Question

C

Chefjay22

Happy Friday everyone. I am currently looking for a little help with a
programming question. I was told by my boss to make a modification to one of
our MS Access applications. Basically she wants to log some data that
appears on a form. I am not a programmer but more of a MS Access Expert
minus the programming lol. Anyways, I did this exercise in 2 seconds using a
MS Access query... but atlas she wants it in code to make my life more
difficult. So here is what I have:

My Function is Named : ImportDateLogging

The form that contains the fields is named frmNewAcct.

On this form I have 2 fields that need to be written to a table called
tblDateLogging

The fields on the form I need to write are called "BegDate" & "EndDate"

These fields need to be writen to tbleDateLogging.FromDate &
tblDateLogging.ToDate respectively.

I already have a new function created, and have a call in the existing code
to call my function... I just need some help on how to do this being the
novice programmer that I am. Thank you so much!
 
R

Robert Morley

Chefjay22 said:
Happy Friday everyone. I am currently looking for a little help with a
programming question. I was told by my boss to make a modification to one of
our MS Access applications. Basically she wants to log some data that
appears on a form. I am not a programmer but more of a MS Access Expert
minus the programming lol. Anyways, I did this exercise in 2 seconds using a
MS Access query... but atlas she wants it in code to make my life more
difficult.

It is the purpose of bosses to make your life more difficult. :)
So here is what I have:

My Function is Named : ImportDateLogging

The form that contains the fields is named frmNewAcct.

On this form I have 2 fields that need to be written to a table called
tblDateLogging

The fields on the form I need to write are called "BegDate" & "EndDate"

These fields need to be writen to tbleDateLogging.FromDate &
tblDateLogging.ToDate respectively.

I'm assuming the "tble" in the first one should just be "tbl".
I already have a new function created, and have a call in the existing code
to call my function... I just need some help on how to do this being the
novice programmer that I am. Thank you so much!

This sounds fairly straight-forward to me. There are actually a myriad of
ways of doing this, but probably the easiest one if you're already adept at
SQL would be to simply run a SQL Insert query from your code. Assuming
you're using an MDB and not an ADP, it would be:

Public Sub ImportDateLogging()
CurrentDB().Execute "INSERT INTO tblDateLogging (FromDate, ToDate) SELECT
#" & Forms!frmNewAcct!BegDate.Value & "#, #" &
Forms!frmNewAcct!EndDate.Value & "#"
End Sub

Or if your code is already passing the values to the Sub/Function, then:

Public Sub ImportDateLogging(ByVal dtFrom As Date, ByVal dtTo As Date)
CurrentDB().Execute "INSERT INTO tblDateLogging (FromDate, ToDate) SELECT
#" & dtFrom & "#, #" & dtTo & "#"
End Sub


Does one of those do what you need it to?


Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Passing Fields to Module for Calculation in Query 2
vb problem 1
Access MS Access VB 0
VB Code not working correct in 2007 1
3008 error by using memo format 0
between dates 9
User name stamp 5
Formating Percent with VB 2

Top