ISLOADED Compile error

M

mma40

I am using the following code to put my user number from Main form into
the New form when open that form but I get a compile error. Can
someone tell me why it does not work? Also SetFocus does not work.

Private Sub Form_Open(Cancel As Integer)
If IsLoaded("Main") Then
Me.UserNumber = Forms!Main!UserNumber
End If

End Sub

Help greatly appreciated.
 
B

Brian Bastl

First, you should make sure that you have the IsLoaded() function in a
standard module (not named "IsLoaded"). If not, then here it is:
'*******************************
Function IsLoaded(ByVal strFormName As String) As Integer
' Returns True if the specified form is open in Form view or Datasheet
view.

Const conObjStateClosed = 0
Const conDesignView = 0

If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <>
conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If

End Function
'*******************************

Otherwise, you might want to move your code to the called form's On Load
event. On Open might be too soon to assign a value, but not 100% certain of
this.

HTH,
Brian
 
M

mma40

Ok, I put in the code and now I get : You can't assign a value to this
object and the debug highlights
Me.UserNumber = Forms!Main!UserNumber
Is this because on the Main form from where I am leaving is an
autonumber? It is not an autonumber on the form I am opening.
 
G

Guest

Try this, it is a little easier:

Private Sub Form_Open(Cancel As Integer)

If currentproject.AllForms("main").IsLoaded Then
Me.UserNumber = Forms!Main!UserNumber
End If

End Sub
 
G

George Nicholson

Are you 1) trying to move to a specific pre-existing record on the form you
are opening, 2) open a form to a new record and "fill in" the specified
UserNumber or 3) do something else?
If you are trying to do #1 (or #3, maybe), you need entirely different code.

HTH,
 
M

mma40

I have a Main form with a subform (subform is not for data entry). On
the main form, I have a command button to open a new form that is used
for data entry. I would like the autonumber from the Main form (which
is my UserNumber) to automatically load onto my new form UserNumber
where visits are recorded. After Saving the entry form, return to my
Main form on the same record with the new data on the subform.
 
G

George Nicholson

OK, I'm thinking that maybe the form doesn't think data entry is allowed.

Is the form you are opening set up for data entry? Is the DataEntry,
AllowAdditions, AllowEdits properties of the Form set to Yes and/or are you
using the acFormAdd for the DataMode argument of OpenForm? If you open the
form manually, can you add a record, or do you get the same message?

HTH,
 

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