Cannot set the value of a textbox

Soma_rich

Registered User.
Local time
Today, 07:50
Joined
May 2, 2007
Messages
58
:banghead:
Not sure whats going on here, nothing on the table that stops this from working. I just get Run-time error "2448 You can't assign a value to this object" When the code runs.

Any ideas what I am doing wrong?

Code:
Private Sub Form_Open(Cancel As Integer)

Dim rst As DAO.Recordset
MySQL = " Select max(ID) from TblUserQry"
Set rst = CurrentDb.OpenRecordset(MySQL)
Myid = rst.Fields(0) + Int(Rnd(1) * 10)

Me.txtMyID.Value = Myid

End Sub
 
Hi

Do you not need to Dim the MySQL and Myid? Try this

Code:
Private Sub Form_Open(Cancel As Integer)

Dim rst As DAO.Recordset
Dim MySQL as String
Dim Myid as String
MySQL = " Select max(ID) from TblUserQry"
Set rst = CurrentDb.OpenRecordset(MySQL)
Myid = rst.Fields(0) + Int(Rnd(1) * 10)

Me.txtMyID.Value = Myid

End Sub

HTH (I may be wrong, I am still learning :)!)
 
Try by moving the code to the form's load event instead.
 
Does txtMyID happen to be bound to an AutoNumber field? Also which line gives you the error?
 
Hi txtMyID is bound to a standard number field, Will try putting it in the on-load event cheers
 
JHB it works a treat in on-load why is form-open different? When would I use form-open over form-load?

Thanks again!
 

Users who are viewing this thread

Back
Top Bottom