Error 2108 You must save the field before you execute the GoToControl

D

Dustin I.

I'm trying to create a nicely formated Name and Address
text box to print on a report. I have created a function
in "module1" and in my report or sub I have code that
looks like :

DisplayAddress(ClientAddress)
txtAddress.Text = ClientAddress

When I first wrote the code I did not have any setfocus's
in there but got an error on that, now that I have added
setfocus on each control that I want to reference I get a
new error 2108 saying that I need to save the field.
Below is the code in my module. When I run this code
directly in a form it works, but when I reference it as a
function it fails, and I can not seem to get the code to
work directly in a report.

Sub DisplayAddress(strAddress)
Dim varName, varA1, varA2, varCity, varState, varZip As
String

Form_InvoiceEntry.clName.SetFocus
varName = Form_InvoiceEntry.clName.Text
Form_InvoiceEntry.clAdd1.SetFocus
varA1 = Form_InvoiceEntry.clAdd1.Text
Form_InvoiceEntry.clAdd2.SetFocus
varA2 = Form_InvoiceEntry.clAdd2.Text
Form_InvoiceEntry.clCity.SetFocus
varCity = Form_InvoiceEntry.clCity.Text
Form_InvoiceEntry.clState.SetFocus
varState = Form_InvoiceEntry.clState.Text
Form_InvoiceEntry.clZip.SetFocus
varZip = Form_InvoiceEntry.clZip.Text
strAddress = varName & vbCrLf & varA1
If Len(varA2) > 0 Then
strAddress = strAddress & vbCrLf & varA2 & vbCrLf
& varCity & " " & varState & " " & varZip
Else
strAddress = strAddress & vbCrLf & varCity
& ", " & varState & " " & varZip
End If
'txtAddressFormated.SetFocus
'txtAddressFormated.Text = strAddress
End Sub


Any help would be greatly appreciated.

Thanks
 
T

TC

I haven't checked your code, but be aware that you normally set the content
of an Access textbox by setting its Value property - not its Text property.
You may be getting mixed-up with VB, where I believe you only have the Text
property.

The Value property is the default property of an Access textbox, so you can
probably just say:

txtAddress = ClientAddress

To explain the difference between the two properties, say you move to a
textbox that is currently displaying the value "xyz". Say you retype that
value to "xQQz". At this point, the Value property is "xyz", and the Text
property is "xQQz". As soon as you exit the textbox, the Value property is
changed to "xQQz", and the Text property becomes unavailable. So in most
cases you would only be reading the Text property - not writing it.

HTH,
TC
 

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

Top