Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

looking for ideas for condensing my code 1

Status
Not open for further replies.

irethedo

Technical User
Feb 8, 2005
429
US
I am looking for ideas on how to condense my code that I have on making certain fields and lines visible on a form depending on certain data that I need to display.

This is a type of a scalable form that changes width (with columns) and certain headings depending on what the form needs to hold but there must be a more compact way of doing this...

In the following code, I have several sections of similar code (7 in all) where the control names are changed to only affect the controls of interest.

In other areas of my code where I have similarly duplicate sections of code I have been able to create substitution variable that work well for loading fields in tables such as:

ThisOP = "Operation" & CurOp ' determine if this is an inspection (last) step
NextOP = "Operation" & CurOp + 1 ' determine if this is an inspection (last) step
OpEnd = "OP" & CurOp & "End" ' set for the correct end date for this operation
EID = "EID" & CurOp

If objrs(NextOP) = "end" Then objrs("CurrentOp") = "record almost complete"
If objrs(ThisOP) = "" Then objrs("CurrentOp") = "record complete"
objrs(EID) = Me.opinit

But I am not sure if this substitution method can be done with controls in the code below:

If Me.OP7 = "" Then
OP7.Visible = False
op7init.Visible = False
Op7date.Visible = False
op7ldate.Visible = False
op7linit.Visible = False
O7line.Visible = False
O7bline.Visible = False
op7head.Visible = False
op7box.Visible = False
system7.Visible = False
Else
OP7.Visible = True
op7init.Visible = True
op7linit.Visible = True
Op7date.Visible = True
op7ldate.Visible = True
O7line.Visible = True
O7bline.Visible = True
op7head.Visible = True
op7box.Visible = True
system7.Visible = False
If Me.OP7 = str Then
O7line.Visible = False
O7bline.Visible = False
system7.Visible = True
op7ldate.Visible = False
op7linit.Visible = False
End If
End If

Is there a way to create substitution variables for the above code to set the attributes of the controls?

Or any other ideas how I might condense my code in an effiecent manner?


Please advise

Thanks!
 
Seeing numbers like this in object (or field) names suggest spreadsheet type thinking. I could be very wrong.

However, you can use syntax like:
Code:
dim intNum as Integer
intNum = 7
If Me("OP" & intNum) = "" Then
    Me("OP" & intNum).Visible = False
    Me("OP" & intNum & "init").Visible = False
    Me("OP" & intNum & "date")Visible = False
    ....

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Thanks Duane... this is what I was looking for!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top