REPORT LBL change

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a delivery address on my report. I have used a lbl for this. Generally
it is right but occasionally I need to have a different delivery address. Is
there a way to change the label on the fly?

I don't want people generally to be able to get to design mode of the report
to change the address. Does anyone have a suggestion?
Thanks
 
This example uses the InputBox function for brevity. In a production app I
would usually use a form instead of the InputBox function, but hopefully
this should serve to illustrate the general idea ...

Private Sub Report_Open(Cancel As Integer)

Dim DeliveryAddress As String

DeliveryAddress = InputBox("Delivery Address?")
If DeliveryAddress = vbNullString Then
Me.Label1.Caption = "Standard delivery address"
Else
Me.Label1.Caption = DeliveryAddress
End If

End Sub
 
Thanks! I kind of understand the concept. But I don't know how to make it
more than one line. And it fires twice once when the form opens and then
again. You said you would use a form. So an address form would have default
whatever the standard address is and if not then they would have the option
of changing it. I think I understand but I will have to think about it for a
bit to get it.

Thanks again.
 
OK, here's a slightly more detailed example. This code would go in the Open
event procedure of the report ...

Private Sub Report_Open(Cancel As Integer)

Dim varDeliveryAddress As Variant

'The acDialog option causes the calling procedure (this
'one) to pause until the form is closed or hidden.
DoCmd.OpenForm "frmDeliveryAddress", , , , , acDialog

'The code will resume here when the user clicks the
'button that hides the form.
varDeliveryAddress =
Forms("frmDeliveryAddress").Controls("txtDeliveryAddress")
DoCmd.Close acForm, "frmDeliveryAddress"

'The label currently contains the standard address, which
'was assigned at design time, so if the variable is Null,
'indicating that the user did not enter a custom delivery
'address, we just leave the label alone.
If Not IsNull(varDeliveryAddress) Then
Me.lblDeliveryAddress.Caption = CStr(varDeliveryAddress)
End If

End Sub

And this is the code behind the Click event procedure of the command button
on the form ...

Private Sub cmdTest_Click()
Me.Visible = False
End Sub
 
Back
Top