REPORT LBL change

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
 
B

Brendan Reynolds

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
 
G

Guest

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.
 
B

Brendan Reynolds

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Report field change on the fly 2
Controlling controls 2
Them delivery services - some good, some not so good 3
Assign string to a Control 13
report problem 1
FillCDays() 14
What Event To Use 3
Sorting 7

Top