Cannot Assign a Value Error

sear100

Registered User.
Local time
Today, 23:38
Joined
Nov 25, 2012
Messages
31
Hi All,

have a form frm_Inpatients with a command button that loads another form frm_PatientInfoSummary. I am trying to pass the primary key (or some other identifiable variable) from one form to another so that it load's the right info in the other form.

My Globals are declared in a seperate module:
glbPatientID as String

The code in the base form frm_Inpatients is
Code:
Private Sub InfoSummary_Click()

Dim patID As Long

patID = Me.intPatientID
glbPatientID = patID

DoCmd.OpenForm "frm_PatientInfoSummary", , , , , acDialog

End Sub

On the other side I have a form who's on Open property recieves the glbPatientID

Code:
Private Sub Form_Open(Cancel As Integer)
   
Me.intPatientID = glbPatientID

End Sub

However this throws an error "cannot assign a value to this object"

I have the same set up which works for another form which opens from the same base form "frm_Inpatients" which works without issue:

Code:
Private Sub BookOperation_Click()
'Opens Booking form in for this patient

On Error GoTo Err_hand

Dim vid As Long
Dim verror As Boolean
Dim crit As String

On Error GoTo err_verror
vid = Me.intPatientID
If verror = True Then
    verror = False
    MsgBox "No Record Selected", vbCritical
   GoTo progout
End If

glbPatientID = vid
glbOperation_ADDNEW = True
DoCmd.OpenForm "frm_Operation", , , , , acDialog
glbOperation_ADDNEW = False

progout:
Exit Sub

err_verror:
verror = True
Resume Next

Err_hand:
MsgBox Err.Description
Resume progout

End Sub

and the code on the "frm_Operation"


Code:
Private Sub Form_Open(Cancel As Integer)

If glbOperation_ADDNEW = True Then
    DoCmd.GoToRecord , , acNewRec
    Me.intPatientID = glbPatientID
End If
glbOperation_ADDNEW = False

End Sub

Can anyone shed light on what's going wrong?
 
The choice of method is the problem ! Try Form Load instead of Form Open
 
Your example above is different to the working one so I would suggest making them them same. Then see where your at...
 
Hi I've tried copying my code between the two and I still get the error! I've also tried the "on Load" method as well....

If it's any help at all on "frm_PatientsInfoSummary" I am using =Trim(....etc ) as one of the text boxes?
 
FYI....The line which hits out the error is
"Me.intPatientID = glbPatientID"
 
I would dbl-check all the names of the controls in your code to make sure they are spelled correctly and exist. Also make sure you are not trying to add a value to a calculated control.
 
Are you trying to open the Form at a particular record? If so the method you are following is wrong.
 
I think he's trying to add a value to a control on the open.

I assume you have gone to a new record?
 
I think he's trying to add a value to a control on the open.

I assume you have gone to a new record?
In that case would not opening the Form at a new record be a more desirable option?
Code:
DoCmd.OpenForm "FormName", DataMode:=acFormAdd, OpenArgs:="theValue"
PS: Just saw you are from Dorset ! I am from Bournemouth, are you somewhere around the same area?
 
Hi pr2-eugin and James,

I'm actually just opening a form which gives a summary field of all the text fields in a table e.g.

=Trim("Diagnosis: " & [txtDiagnosis] & (Chr(13)+Chr(10)+"Surgery: "+[dtmLastSurgeryDate]+"| "+[txtSurgeryText]) & (Chr(13)+Chr(10)+" |Complication: "+[txtMandMType]+" Details: "+[txtMandMText]) & (Chr(13)+Chr(10)+" Presentation: " & [txtPresentation]).... etc

All i want is a pop up form that collates this information so that a user can copy this for use elsewhere (on a webform/email or MS word document specifically).

I suspect I may be using the wrong method! The above method was copied across from another process that I was using. I assumed it would work.

Could you suggest a more simple solution?
 
After essentially a trial and error process this finally worked - I avoided the "pass me a variable" routine entirely.

To open another form based on the Primary key of the form that you are coming from

Code:
Private Sub YOURBUTTON_Click()

Dim vid As Long
Dim crit As String

vid = Me.YOURPRIMARYKEY
crit = "YOURPRIMARYKEY = " & vid

DoCmd.OpenForm "SOMEFORM", acNormal, , crit, , acDialog

End Sub

Seems to work!
 
Last edited:

Users who are viewing this thread

Back
Top Bottom