error: you can't reference a property or method...

emshim

Registered User.
Local time
Today, 19:55
Joined
Sep 6, 2007
Messages
55
Access error: you can't reference a property or method for a control unless the co...

Hi,

Can someone tell me what this error means? "You can't reference a property or method for a control unless the control has the focus. It is to do with a text box on a form, checking whether it has text in it or if it is blank.

Emily
 
Last edited:
Don't use the .Text property, use the .Value property.
 
ok thats great thanks! 1 more thing, i am trying to get my command button to open another form if a specific text box is blank. I can get it to do this if i have a specific value typed in, of my choice, but as soon as i want to have it blank, it does not respond. I thought i could just type:

If textbox.value = "" then
DoCmd.Open......
.....
End If

But this does not work. If i put a value between these speech marks i.e. "A" and type A in the text box, the form will now open.

Thanks in Advance,

Emily
 
ah i cracked it! Thanks anyway.

i ended up writing:

stDocName2 = "frmStock"
if isNull(txtCustomerNumber.value) Then
DoCmd.OpenForm stDocName2
End If

Thanks for the help previously R G!!!

Em
 
You're welcome. If you use:
If Len(Me.txtCustomerNumber & "") = 0 Then
...it will cover both an empty field and a Null field. FYI, because the .Value property is the default property, you do not actually need to specify it in your syntax.
 
ah brilliant, ill use that, that would be better! Thanks!

em
 
ha got another problem now:

i want to click on a button which will look at a number in a field on a form, open up the new form, and find that number. If the number is not in the table, it shows a blank (this is the part i was doing a minute ago) I can get everything to work on their specific forms but i want it all to happen in the click of one button. At the moment, they click on the button and it finds the record. I have another button which recognises the field is blank and will take the user to the other form. I want the first button to find the record if there is a match, and go to the other form if there is not.

The code i have at the moment is this: (sorry if its rubbish, im quite new 2 all of this)

(This part is when the button is clicked on the first form, and a customer number has been written in text2. Customer number is in a different table, and is the thing i am searching on. This works by the way)

stDocName2 ="frmStock"
stDocName = "frmAllocate"
stLinkCriteria= "[CustomerNumber]=" & "'" & Me![text2] & "'"
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria

I then have the records appear which match the customer number. I then have, for the button on the form which has opened...)

stDocName = "frmStock"
If IsNull(txtCustomerNumber.Value) Then
MsgBox"There are no items reserved for this customer"
DoCmd.OpenForm stDocName
End If

(This again works fine, but obviously, the customer can already see that the box is blank and can tell no items have been reserved by themselves. Instead of showing this, i want it to go straight to the next form.)

I think ive repeated myself many times here, and made a complete mess of what im trying to ask, but if you understand, please try and help!

Thanks again,

Emily
 
Look into the DCount() function with "[CustomerNumber]=" & "'" & Me![text2] & "'" as the criteria and that will allow you to decide which form to open. Post back if you need additional assistance.
 
sorry, RG, i dont fully understand what you mean by the previous post.

emily
 
Have you looked at DCount() in VBA Help? It can tell you if there are any records for the "frmAllocate" to process. If not then open the "frmStock" form instead.
 
thanks for the help. I have worked out how to complete this task in a different way somehow! But thanks anyway R G, you have been very helpful!

Emily
 

Users who are viewing this thread

Back
Top Bottom