Adjusting line in Access VB - ms-access

I've seen a number of question/answers on how to adjust the height of lines when the detail section expands; however, haven't seen anything about line width.
I got the line to adjust height by using:
Dim CtlDetail As Control
Dim intLineMargin As Integer
intLineMargin = 0
For Each CtlDetail In Me.Section(acDetail).Controls
With CtlDetail
If CtlDetail.Name = "Line192" Or CtlDetail.Name = "Line193" Then
Me.Line ((.Left + .Width + intLineMargin), 0)-(.Left + .Width + intLineMargin, Me.Height)
End If
End With
Next
Set CtlDetail = Nothing
End Sub
BUT, while the line does adjust height the width reverts back to "hairline" rather than the points I prefer.
Thanks for any help I appreciate it.

Related

Problem setting width in dynamically created textbox in vb.net

I use these lines to dynamically create buttons and text boxes.
For i As Integer = 1 To 100
Dim newButton = New Button()
newButton.Text = i
newButton.ID = i
newButton.CommandName = i
newButton.Style.Add("width", "20%")
newButton.Style.Add("height", "100%")
Panel1.Controls.Add(newButton)
Next
For i As Integer = 1 To 100
Dim newtext = New TextBox()
newtext.TextMode = TextBoxMode.MultiLine
newtext.Style.Add("width", "20%")
newtext.Style.Add("height", "100%")
Panel2.Controls.Add(newtext)
Next
While the buttons fit the page width correctly, text boxes leave a space to the right.
1 2
I've tried assigning a class instead of width, but it doesn't work.
"min-width" also doesn't work.
How to set the text boxes to fit the page width?
I resolved setting textbox border-width and padding to zero pixels.
newtext.Style.Add("border-width", "0px")
newtext.Style.Add("padding", "0px")

Make a continuous form set its height automatically

I am trying to make a continuous form set its height to equal the height of the Header + height of Footer + height of the Detail. This is to avoid having a form with only two or three records have a large amount of blank space. Conversely I want to have a large number of records appear on a form with 10 records per page and arrow Down/Up to see the rest of the records.
These are the procedures I set up:
Public Function NumRecs() As Integer
NumRecs = DCount("*", "tblDisclosure", "Not IsNull(FormSentOff) and IsNull(DBSInvoice))
End Function
Public Function FrmHt() As Integer
Dim FrmDet As Integer
Dim FrmHdr As Integer
Dim FrmFtr As Integer
FrmDet = Form.Section(0).Height
FrmHdr = Form.Section(1).Height
FrmFtr = Form.Section(2).Height
If FrmHt > (11 * FrmDet + FrmHdr + FrmFtr) Then
FrmHt = 11 * FrmDet + FrmHdr + FrmFtr
Else
FrmHt = (NumRecs * FrmDet) + FrmHdr + FrmFtr + FrmDet
End If
End Function
Private Sub Form_Load()
Me.Move Left:=8000, Top:=1000, Width:=9240, Height:=FrmHt
End Sub
It ignores the If…Then… Else statement and creates a form showing all records in one window
which is unmanageable.
It works for a form of less than 11 records (obviously) but I find that I have to add in the height
of an extra record otherwise it puts the last record on a second page. Viz:
FrmHt = (NumRecs * FrmDet) + FrmHdr + FrmFtr + FrmDet
I can live with this but I would really like to resolve the problem of the If…Then…Else statement being ignored.
I have changed the type casting to Variant and Double but this made no difference.
There seems to be an issue your code: you use FrmHt in your If statement, but it has no value at that point, it will always be 0.
I think you probably want your statement to be something like:
If NumRecs > 11 Then
FrmHt = 11 * FrmDet + FrmHdr + FrmFtr
Else
FrmHt = (NumRecs * FrmDet) + FrmHdr + FrmFtr + FrmDet
End If
The other issue of the last record being on the next page may be because you're too tight in displaying the 10 records on screen and during the conversion from twips to pixels rounding errors may make the total height a tiny bit less than what would be necessary for 10 records.
Try adding a few twips to your FrmHT result to see if this works.

ms access - set position of cursor in textfield to start only if textbox is empty

What I would like to do is in my formatted (inputmask) textbox set the cursor position to the first position if there is nothing in the textbox. BUT if there is something set the position to where ever the user clicked.
Right now I have:
If (txtCR.Value = "" Or IsNull(txtCR.Value)) Then
Me.txtCR.SelStart = 0
End If
But even if there is something in the textbox the cursor is moved to the first position.
Is there a way to do this?
Thanks!
Maybe this will work for you? (MsgBox line to see if you are getting the right value. You can take it out for production, obviously.)
If (txtCR.Value = "" Or IsNull(txtCR.Value)) Then
Me.txtCR.SelStart = 0
Else
Me.txtCR.SelStart = Me.txtCR.SelStart + Me.txtCR.SelLength
End If
MsgBox Me.txtCR.SelStart

VBA - Reorder Access 2010 Navigation Form Tab Index

Is there a way to dynamically reorder the navigation buttons on the Access 2010 Navigation Form?
I would like to hide certain buttons depending on user type; however simply hiding them leaves a gap between buttons if the order cannot be modified.
I have tried similar to the following with no luck.
Me.NavigationButton1.TabIndex = 1
Me.NavigationButton2.TabIndex = 0
Me.Requery
Me.Refresh
Thank you in advance.
NavigationButtons work a bit differently. They are managed in a NavigationControl container that does not resize automatically if underlying buttons are hidden.
However, you can try this, it works for me:
' Always remember the normal size of the button '
Static bt1Witdh as Long
if bt1Width = 0 then bt1Width = Me.NavigationButton1.Width
' Now hide the button '
Me.NavigationButton1.Width = 0
Me.NavigationButton1.Visible = False
' Unhide the button '
Me.NavigationButton1.Visible = true
Me.NavigationButton1.Width = bt1Width
You can make this a lot more generic and a bit 'hacky' by using the control's Tag property as a temporary storage for keeping track of their normal width:
Public Sub HideNavigationButton(bt As NavigationButton)
' Store the width if we haven't already done so '
If bt.Tag = vbNullString Then bt.Tag = CStr(bt.Width)
bt.Width = 0
bt.Visible = False
End Sub
Public Sub ShowNavigationButton(bt As NavigationButton)
If bt.Visible Or bt.Width > 0 Then Exit Sub
bt.Visible = True
bt.Width = CInt(bt.Tag)
End Sub
To use it:
' Hide '
HideNavigationButton Me.NavigationButton1
' Show '
ShowNavigationButton Me.NavigationButton1

ms-access/VBA: invalid reference to the scalemode property (error on adding a border to a report)

I'm trying to use the following function to draw a border around my report:
Public Function PageBorder(ByVal strReportName As String)
Dim Rpt As Report, lngColor As Long
Dim sngTop As Single, sngLeft As Single
Dim sngwidth As Single, sngheight As Single
On Error GoTo PageBorder_Err
'DRAW DOUBLE LINED BORDER
Set Rpt = Reports(strReportName)
'Set scale to pixels
Rpt.ScaleMode = 3
'Top inside edge
sngTop = Rpt.ScaleTop
'Left inside edge
sngLeft = Rpt.ScaleLeft
'Width inside edge
sngwidth = Rpt.ScaleWidth
'Height inside edge
sngheight = Rpt.ScaleHeight
'color value
lngColor = RGB(0, 0, 255)
'Draw page Border
Rpt.Line (sngTop, sngLeft)-(sngwidth, sngheight), lngColor, B
sngTop = Rpt.ScaleTop + 10
sngLeft = Rpt.ScaleLeft + 10
sngwidth = Rpt.ScaleWidth - 10
sngheight = Rpt.ScaleHeight - 10
Rpt.Line (sngTop, sngLeft)-(sngwidth, sngheight), lngColor, B
PageBorder_Exit:
Exit Function
PageBorder_Err:
MsgBox Err.Description, , "PageBorder"
Resume PageBorder_Exit
End Function
(source: http://msaccesstips.com/2007/08/reports-page-border/)
I added pageborder "myreport" to my report_open, but it returns the following error:
error 2455: invalid reference to the scalemode property.
anyone have any clue about this ?
Try the On Page event.
Access help: "You can set the ScaleMode property by using a macro or a Visual Basic event procedure specified by a section's OnPrint property setting."