#Type In access form (1 Viewer)

luzz

Registered User.
Local time
Yesterday, 22:39
Joined
Aug 23, 2017
Messages
346
Hi everyone, two of the fields in my form show #Type when i click on the button "Clear" on my form.

My code:
Me.txtID = ""
Me.txtColour = ""
Me.txtGrossweight = ""
' Me.txtNettweight = ""
Me.txtLbs = ""
' Me.txtLoss = ""
Me.txtRemarks = ""

I Comment out nettweight and loss because it does not allow me to run if i dont comment it out.

I used expression builder in txtNettWeight and txtLoss for calculation

how can get rid of #Type in my form?
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 15:39
Joined
Jan 20, 2009
Messages
12,850
The controls are probably bound to a numeric field.
"" is a string so it is the wrong Type.

Try Null instead.
 

luzz

Registered User.
Local time
Yesterday, 22:39
Joined
Aug 23, 2017
Messages
346
The controls are probably bound to a numeric field.
"" is a string so it is the wrong Type.

Try Null instead.

null = Nz(txtNettWeight,"")?
 

Minty

AWF VIP
Local time
Today, 06:39
Joined
Jul 26, 2013
Messages
10,366
You have calculations driving the values in those controls.
Therefore add a Nz() around the calculations, don't try and override the controls value.

You can't set null to anything. Null is Null
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 15:39
Joined
Jan 20, 2009
Messages
12,850
You can't set null to anything. Null is Null

That is not correct. Null can be assigned as the Value of a control or field.

I still believe my previous post probably identified the real problem.

The controls are probably bound to a numeric field.
"" is a string so it is the wrong Type.

Try Null instead.

Code:
Me.txtNettweight = Null
You have calculations driving the values in those controls.

If it were the case that the textbox had a calculated ControlSource then the error message would be:
Code:
You can't assign a value to this object
 

luzz

Registered User.
Local time
Yesterday, 22:39
Joined
Aug 23, 2017
Messages
346
That is not correct. Null can be assigned as the Value of a control or field.

I still believe my previous post probably identified the real problem.



Code:
Me.txtNettweight = Null

If it were the case that the textbox had a calculated ControlSource then the error message would be:
Code:
You can't assign a value to this object



I tried me.txtnettweight = null and it show me error"You can't assign a value to this object"

and yes i do have control source to it
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 15:39
Joined
Jan 20, 2009
Messages
12,850
I tried me.txtnettweight = null and it show me error"You can't assign a value to this object"

and yes i do have control source to it

So the Value Type compatibility test which raised the error is applied prior to the updateability test that Minty identified.

We were both right in a way.:cool:

Thanks for posting back with the clarification.
 

Minty

AWF VIP
Local time
Today, 06:39
Joined
Jul 26, 2013
Messages
10,366
So the Value Type compatibility test which raised the error is applied prior to the updateability test that Minty identified.

We were both right in a way.:cool:
I knew it :p
 

luzz

Registered User.
Local time
Yesterday, 22:39
Joined
Aug 23, 2017
Messages
346
You have calculations driving the values in those controls.
Therefore add a Nz() around the calculations, don't try and override the controls value.

You can't set null to anything. Null is Null

I tried this method and it still wont work
 

almahmood

Registered User.
Local time
Today, 11:09
Joined
Mar 28, 2017
Messages
47
I tried me.txtnettweight = null and it show me error"You can't assign a value to this object"

and yes i do have control source to it

I think you are using calculation on txtNettWeight control. If so, you won't be able to set null value in it. Always use Nz() in your calculation to obsolete the null value. Set null value only those are not calculated fields.
 

luzz

Registered User.
Local time
Yesterday, 22:39
Joined
Aug 23, 2017
Messages
346
I think you are using calculation on txtNettWeight control. If so, you won't be able to set null value in it. Always use Nz() in your calculation to obsolete the null value. Set null value only those are not calculated fields.

Yes you are right, Nettweight and loss have calculation
 

luzz

Registered User.
Local time
Yesterday, 22:39
Joined
Aug 23, 2017
Messages
346
Hello peeps, Can you all take a look at my database and tell me where i go wrong? have been stuck with this for a long time
 

Attachments

  • Database.zip
    74.8 KB · Views: 228

moke123

AWF VIP
Local time
Today, 01:39
Joined
Jan 11, 2013
Messages
3,908
I dont use Ado so just taking a guess.
Since your using an unbound form but the offending field is calculated based on an unbound control, Can you do the calculation in your recordset and leave Netweight as an unbound control also?

edit: just tried it and it appears you can.
Add the calculation to your Display procedure and make the control unbound
 
Last edited:

luzz

Registered User.
Local time
Yesterday, 22:39
Joined
Aug 23, 2017
Messages
346
I dont use Ado so just taking a guess.
Since your using an unbound form but the offending field is calculated based on an unbound control, Can you do the calculation in your recordset and leave Netweight as an unbound control also?

edit: just tried it and it appears you can.
Add the calculation to your Display procedure and make the control unbound

i have no idea how to continue the code on my display tho
 

Minty

AWF VIP
Local time
Today, 06:39
Joined
Jul 26, 2013
Messages
10,366
I have no idea why you are using an unbound form, and are using an ADO recordset to connect to a local table.

It's completely pointless, and causing you endless amounts of unnecessary code, and issues which you haven't currently the experience to fix.

Why use ADO?
And why use a unbound form?
 

luzz

Registered User.
Local time
Yesterday, 22:39
Joined
Aug 23, 2017
Messages
346
I have no idea why you are using an unbound form, and are using an ADO recordset to connect to a local table.

It's completely pointless, and causing you endless amounts of unnecessary code, and issues which you haven't currently the experience to fix.

Why use ADO?
And why use a unbound form?

I use ADO as at the end of the project, i will be retrieving excel spreadsheet from a local desktop and not from the local table.
 

Minty

AWF VIP
Local time
Today, 06:39
Joined
Jul 26, 2013
Messages
10,366
Just link to the spreadsheet, or import it.
 

moke123

AWF VIP
Local time
Today, 01:39
Joined
Jan 11, 2013
Messages
3,908
i have no idea how to continue the code on my display tho
although I agree with minty,
just add the calculation to the display procedure.
Code:
Public Sub display()
'To show the retrieve data onto form
'
txtHQPO = rsTable1!PO
'
txtFabric = rsTable1!Fabric
'
txtColour = rsTable1!Colour
'
txtPound = rsTable1!SumofPounds
'
txtNettweight = rsTable1!SumofPounds / 2.2

End Sub
also note this should be a private sub not public and
you do not need to set focus to each control (removed them above)
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 06:39
Joined
Sep 12, 2006
Messages
15,632
if a control has a calculation, such as

= a x b

then you get it to update to zero, by setting elements a and b to zero.

You can't set the result of the calculation directly, which is what others have been pointing out.
 

Users who are viewing this thread

Top Bottom