Using MS Access 2013: If Then Statement for continuous Form Issue - ms-access-2013

I need this to effect only the current record within the continuous form.
On the Offender Type I select "offender 1" and the code correctly sets all four fields not enabled.
However when I go record 2, in the Offender Type, I select "Offender 2" the code incorrectly sets all four fields to enabled of every record of the continuous form not just the fields for record 2.
Combo box Name: Offender_Type
Selections for Offender_Type: Offender 1; Offender 2; Offender 3
Private Sub Offender_Type_AfterUpdate()
If Me.Offender_Type.Value = "offender 1 " Then
Me.Field1.Enabled = False
Me.Field2.Enabled = False
Me.Field3.Enabled = False
Me.field4.Enabled = False
ElseIf Me.Offender_Type.Value <> "offender 1" Then
Me.Field1.Enabled = True
Me.Field2.Enabled = True
Me.Field3.Enabled = True
Me.field4.Enabled = True
Else
End If
End Sub

Related

How to split the reports in a single dataset to Multiple Datasets uisng JCL

A dataset has many reports in it. I need the first report alone to another dataset. How can we achieve using JCL?
Below is the sample how the dataset looks like. My requirement is to sort out only the records under R0A report.
---Report - R0A---
List of Payments
Date : 23/07/2021
Name Payment-Amt Due-Date
AAAA 233.04 15/08/2021
BBBB 38.07 16/08/2021
---Report - R0B---
List of Payments
Date : 23/07/2021
Name Payment-Amt Due-Date
AAAA 233.04 15/08/2021
BBBB 38.07 16/08/2021
---Report - R0C---
List of Payments
Date : 23/07/2021
Name Payment-Amt Due-Date
AAAA 233.04 15/08/2021
BBBB 38.07 16/08/2021
If the size of the reports is fixed, you can use sort with the COPY and STOPAFT= options:
SORT FIELDS=COPY,STOPAFT=6
If you need a report beyond the first, you can add the SKIPREC= option. E.g. to get the third report, specify:
SORT FIELDS=COPY,SKIPREC=12,STOPAFT=6
If the reports differ in length, you could run a simple REXX.
/* REXX - NOTE This is only a skeleton. Error checking must be added. */
/* This code has not been tested, so thorough testing is due. */
"ALLOC F(INP) DS('your.fully.qualed.input.data.set.name') SHR"
"EXECIO * DISKR INP ( STEM InpRec. FINISH"
"FREE F(INP)"
TRUE = 1
FALSE = 0
ReportStartIndicator = "---Report"
ReportName = "- R0B---"
ReportHeader = ReportStartIndicator ReportName
ReportCopy = FALSE
do ii = 1 to InpRec.0 while ReportCopy = FALSE
if InpRec.ii = ReportHeader
then ReportCopy = TRUE
end
if ReportCopy
then do
OutRec.1 = InpRec.ii
Outcnt = 1
do jj = ii + 1 to InpRec.0 while ReportCopy = TRUE
if word( InpRec.jj, 1 ) = ReportStartIndicator /* Start of next report? */
then ReportCopy = FALSE
else do
OutCnt = OutCnt + 1
OutRec.Outcnt = InpRec.jj
end
end
"ALLOC F(OUT) DS('your.fully.qualed.output.data.set.name')" ,
"NEW CATLG SPACE(......) RECFM(....) LRECL(....)"
"EXECIO" OutCnt "DISKW OUT ( STEM OutRec. FINIS"
"FREE F(OUT)"
say "Done copying report." OutCnt "records have been copied."
end
else do
say "Report" ReportName "not found."
exit 16
end
As written in the comment in the REXX, I haven't tested this code. Also, error checking need to be added, especially for TSO HOST commands (ALLOC, EXECIO, FREE).
All of the solutions copy a single report to another data set. In the title, you wrote to multiple datasets. I'm sure you'll find solutions for this using above single report solutions.

How to check if two or more conditions are met vs only one of them is true?

I'm using the following script with a software which reads a CheckBox using OMR and outputs the data to an XML file.
Is there a way I can change it to say if more than one box has been checked, the data output should be the first checked box in the list?
Hope this makes sense.
Any help would be appreciated.
Dim installer
q_a1= Metadata.Values("OMR_FRED_P2")
q_a2= Metadata.Values("OMR_JON_P2")
q_a3= Metadata.Values("OMR_MATT_P2")
q_a4= Metadata.Values("OMR_STEVE_P2")
If q_a1 = "Filled" Then
installer = "Fred"
End If
If q_a2 = "Filled" then
installer = "Jon"
End If
If q_a3 = "Filled" then
installer = "Matt"
End If
If q_a4 = "Filled" then
installer = "Steve"
End If
call Metadata.SetValues("CompleteBy",installer)
You could do something like this:
Dim a1Checked, a2Checked, a3Checked, a4Checked
Dim numberOfChecked
a1Checked = (q_a1 = "Filled")
a2Checked = (q_a2 = "Filled")
a3Checked = (q_a3 = "Filled")
a4Checked = (q_a4 = "Filled")
numberOfChecked = Abs(a1Checked + a2Checked + a3Checked + a4Checked)
If a1Checked Or numberOfChecked > 1 Then
installer = "Fred"
ElseIf a2Checked Then
installer = "Jon"
ElseIf a3Checked Then
installer = "Matt"
ElseIf a4Checked Then
installer = "Steve"
Else
' Decide what you want to do if none is checked.
End If
Call Metadata.SetValues("CompleteBy", installer)
In VBScript, the numeric value of a "boolean true" value is -1 and of the false value is 0.
The above code simply adds the values together. If two conditions are met, the total would be -2, then we use the Abs function to get the abstract value (i.e., returning 2 instead of -2). After that, you can easily check if two or more conditions are met by using numberofChecked > 1.

Using Option Group Toggle Buttons to Filter Data in Form

I have an Access 2010 database with a form that pulls up a list of all of the students that a teacher teaches. One of the fields is "Classperiod"; each teacher teaches 5 classes. I have a set of toggle buttons in an option group (Frame 103) that I'd like to use to filter the list of records by "Classperiod". So, for example, clicking on one of the toggle buttons would only show students from a particular class. Here's the code that I have for the option group in the "After Update" of the Events for the option group:
Private Sub Frame103_AfterUpdate()
Select Case Frame103
Case 1
Me.Filter = "Schedules.Classperiod = 1"
Me.FilterOn = True
Case 2
Me.Filter = "Schedules.Classperiod = 2"
Me.FilterOn = True
Case 3
Me.Filter = "Schedules.Classperiod = 3"
Me.FilterOn = True
Case 5
Me.Filter = "Schedules.Classperiod = 5"
Me.FilterOn = True
Case 6
Me.Filter = "Schedules.Classperiod = 6"
Me.FilterOn = True
Case 7
Me.Filter = "Schedules.Classperiod = 7"
Me.FilterOn = True
Case 8
Me.Filter = "Schedules.Classperiod = 8"
Me.FilterOn = True
Case Else
Me.FilterOn = False
End Select
End Sub
Schedules is the Table that Classperiod is a field for.
Right now the code isn't doing anything. Any suggestions would be welcome!
Your filter can still work if you remove your "Schedule". Just use the fieldname:
Eg.
Case 7
Me.Filter = "Classperiod = 7"
Me.FilterOn = True
The best way however, would be to restrict your record source by the data meeting your criteria:
eg:
Case ....
Me.RecordSource = "Select * FROM Schedules WHERE Classperiod =..."
Me.Requiry
....
If you want to filter based on five different class periods, make your option group with five toggle buttons, the caption of each corresponding to a different class period e.g. toggle button 1 has caption "1" and so on. Here's the code:
Private Sub Frame103_Click()
Dim Caption As String
Caption = Frame103.Controls.Item(Frame103.Value - 1).Caption
Me.SubformName.Form.Filter = "[Classperiod] = """ & Caption & """"
Me.SubformName.Form.FilterOn = True
End Sub

Switch-Hide pictures based on cell values

I am not an expert on VBA, all I know is based on browsing internet, but some simple codes work for me well.
I am switching pictures based on P52 value, that works perfectly, but then I want to swich different pictures based on cell value P117 and that part of the code does not really work for me. What am I missing in the code?
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If Target.Address <> "$P$52" Then Exit Sub
With ActiveSheet
Select Case Target.Value
Case "Horizontal - feet"
.Pictures("B3A").Visible = True
.Pictures("V1A").Visible = False
.Pictures("V1AF").Visible = False
Case "Vertical - simple"
.Pictures("B3A").Visible = False
.Pictures("V1A").Visible = True
.Pictures("V1AF").Visible = False
Case "Vertical - lantern"
.Pictures("B3A").Visible = False
.Pictures("V1A").Visible = False
.Pictures("V1AF").Visible = True
End Select
End With
If Target.Address <> "$P$117" Then Exit Sub
With ActiveSheet
Select Case Target.Value
Case "Right"
.Pictures("3P1").Visible = True
.Pictures("3P1M").Visible = False
Case "Left"
.Pictures("3P1").Visible = False
.Pictures("3P1M").Visible = True
End Select
End With
End Sub
Thanks for your help.
Think through the logic of your if statements causing you to exit the sub.
If the cell is P117, you will hit the first if statement which causes you to exit the sub immediately. So you will never get to your second check.
Embed the logic for each of your operations in if statements like I show here and you will be able to "do something if the cell range is P52 or P117" a bit more appropriately.
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
'only do the following operation if your cell address is P52 - don't exit out
'of your entire code if it's not
If Target.Address = "$P$52" Then
With ActiveSheet
Select Case Target.Value
Case "Horizontal - feet"
.Pictures("B3A").Visible = True
.Pictures("V1A").Visible = False
.Pictures("V1AF").Visible = False
Case "Vertical - simple"
.Pictures("B3A").Visible = False
.Pictures("V1A").Visible = True
.Pictures("V1AF").Visible = False
Case "Vertical - lantern"
.Pictures("B3A").Visible = False
.Pictures("V1A").Visible = False
.Pictures("V1AF").Visible = True
End Select
End With
End If
'you skip to down here if it is NOT P52, which then lets you check again to
'see if it's P117
If Target.Address = "$P$117" Then
With ActiveSheet
Select Case Target.Value
Case "Right"
.Pictures("3P1").Visible = True
.Pictures("3P1M").Visible = False
Case "Left"
.Pictures("3P1").Visible = False
.Pictures("3P1M").Visible = True
End Select
End With
End If
End Sub
If you are going to have a lot of checks like this, you may want to create a Select case statement for Target.Address too. It's hard to say which is better for you given what you've asked here.

VBScript MS-Word Find & Replace Char for Addin Fields

Okay, I've searched and searched and am hoping someone here can help me out.
I've been trying to get a VBScript program to open a word document, search for a specific char and replace it with a Addin field (i.e. { SEQ # } )
Here's what I have thus far:
1 Const wdReplaceAll = 2
2 Set objWord = CreateObject("Word.Application")
3 objWord.Visible = True
4
5 Set ObjDoc = objWord.Documents.Open("C:\path\to\.doc")
6 Set objSelection = objWord.Selection
7
8 objSelection.Find.Text = "#"
9 objSelection.Find.Forward = True
10 objSelection.MatchWholeWord = True
11
12 objSelection.Find.Replace.Text = "replacement text"
13
14 objSelection.Find.Execute ,,,,,,,,,,wdReplaceAll
This code works for "Find/Replace" but does not work for fields.
Much help would be awesome! Thanks!
Replace replaces text, but you want to add a field. That's an entirely different thing. I'd suggest to Find the search text (leaves the text selected) and then Add the field (replaces the selected text):
With objWord.Selection
.Find.Text = "#"
.Find.Forward = True
.Find.MatchWholeWord = True
.Find.Execute
.Fields.Add .Range, -1, "SEQ #", True
End With
To replace all occurrences of the search string you have to create a loop that keeps executing .Find.Execute until no further occurrences are found. The return value of the Execute method indicates if another match was found.
With objWord.Selection
.Find.Text = "#"
.Find.Forward = True
.Find.MatchWholeWord = True
Do
found = .Find.Execute
If found Then .Fields.Add .Range, -1, "SEQ #", True
Loop While found
End With
Make sure your cursor is positioned at the beginning of the document before you run the above code, otherwise you might miss occurrences of your search text.

Resources