VBA with Access Reports

MakinBacon91

New Member
Joined
Sep 8, 2015
Messages
47
Hello All,

I have a report that is grouped by JobID,
I would like to add some VBA that will format a text box in each group section.

I want a text box that will dynamically display a "Priority Date"
This Priority date will be different for each job or nonexistent.
I want to check this JobDate table, and then set the "Priority Date" to the available date, or leave it blank.

JobIDSendS&ICompletePre-CoatShipDate
DUK-150111/30/2015

DUK-1502
12/11/2015
DUK-1503

12/11/2015

<caption> JobDate </caption><thead>
</thead><tbody>
</tbody><tfoot></tfoot>

I am fairly good with vba, but I do not know how to perform this check for each item in the group (each JobID).

Here is a little bit of the code I am working on:
Code:
    Dim str_jobID As String, str_SQL As String, rs As Recordset, str_return As String
    
    str_jobID = Me.GroupLevel(1).ControlSource
    
    str_SQL = "SELECT JobDate.JobID, JobDate.[SendS&I], JobDate.[CompletePre-Coat], JobDate.ShipDate FROM JobDate WHERE (((JobDate.JobID)=" & str_jobID & "));"
    Set rs = CurrentDb.OpenRecordset(str_SQL)
    
    If rs("SendS&I") > "" Then
        str_return = "SendS&I"
    ElseIf rs("CompletePre-Coat") > "" Then
        str_return = "CompletePre-Coat"
    ElseIf rs("ShipDate") > "" Then
        str_return = "ShipDate"
    Else
        str_return = " "
    End If
    
    txt_priorityDate.ControlSource = str_return
    txt_jobID.ControlSource = str_jobID

I just don't know where to put my code so that it will run every time a new item is formed in the group.


Let me know if I can clarify anything.

Thanks!
-Bacon-
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Without seeing the report items I'm not entirely sure what is coming from or going to where, however, generically speaking I would create a VBA function that takes the JobID as input and give the priorityDate as an output.

e.g.
Code:
Public Function GetPriorityDate(strJobID as string) as String
...
your code to determine str_return PriorityDate based on strJobID
...
GetPriorityDate = str_return
End Function

I believe you can then set the Control Source of txt_priorityDate to
=GetPriorityDate([txt_jobID])
and it will run it automatically by group.
 
Upvote 0
Without seeing the report items I'm not entirely sure what is coming from or going to where

Let me try and explain a little better.
Here is an image for the report I am working on: Pasteboard — Uploaded Image

Here are some sample tables
Job Info:
JobIDUnitIDSetNoStatus
1DUK1501Open
2LSP1502Open
3DUK1502Open
4DUK1503Open
5DUK1504Open
6DUK1505Open
7DUK1506Open

<tbody>
</tbody>


JobDate:
JobIDSendS&ICompletePre-CoatShipDate
DUK-150111/30/2015

DUK-1502
12/11/2015
DUK-1503

12/11/2015

<tbody>
</tbody>

So basically what I am trying to do is write some VBA code to fill in the "Priority Date" field with either the S&I Date, Pre-Coat Date, Ship Date, or to completely remove the box and label if there is no Date set.
 
Upvote 0
Options that come to mind:
1) add the priority field to your report query and use the sql statement you have in code as a sub query and bind the report control to it.
2) put your code in one of the report section events (e.g. group section OnPrint event, or Format event). The report does not have to be printed to fire the OnPrint event. Note also that some of these events don't provide the desired outcome in report view, but work in print preview.
3) try placing your code in a standard module and call it from the unbound priority control (what I believe BiocideJ suggested).
However, if you mean you actually want to remove the control if there's no date, I don't believe you can do that at a group level. I think you'd remove it for all. I think you can hide it for a group though I don't recall ever trying.
 
Upvote 0

Forum statistics

Threads
1,221,831
Messages
6,162,252
Members
451,757
Latest member
iours

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top