Code not working when attached to form

T

TimH

Thank you in advance

My code (with help from John Spencer) works as an example however when I
attach it to my form I have runTime-errorrs

Public Function BuildKey()

Dim strTmp As String
Dim dtVisitDate As Date
Dim strSSN As String
Dim Build_Key_ As String


strTmp = InputBox("Please enter visit Date Here:", "Visit Date")****when I
try to
*strTmp= Me.VisitDate--this is bound to visit date on Table of Patients

If IsDate(strTmp) Then
dtVisitDate = DateValue(strTmp)
strTmp = Format(dtVisitDate, "mmddyyyy") 'yyyymmdd
End If


strTmp = strTmp & "-"

strSSN = InputBox("Please enter Full SSN here:", "SSN")***
*strTmp = Me.SSN this is bound to SSN of tblPatients
' OK so it works, I used the code below to take a full SSN
' and convert it to the last 4


strSSN = Right(strSSN, 4)

strTmp = strTmp & strSSN

Build_Key_ = strTmp

Debug.Print strTmp
'Debug.Print Build_Key_
MsgBox "your key is:" & Build_Key_***this is KEY bound to tblPatient

End Function

what am I doing wrong?
once again thank you.
 
T

TimH

the strTmp=InputBox(....) is changed to the VisitDate(Bound) ie:

strTmp = Me.Form.VisitDate
 
J

John Spencer

If ME.VisitDate is bound to a date field, you cannot assign it to strTmp (a
string variable) unless you force it to convert

The most reliable way to do this would be to concatenate an zero-length
string to the end

strTmp = Me.VisitDate & ""


--
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
T

TimH

Associated question:

I have the ptKey (Key) Bound to tblPatents , and I associated (tried many
times)
on different events of the (KEY) ie- on dirty, before update, onGotFocus,
but all
in vain, the code will not place the generated KEY in the Field.

What am I overlooking;
as allways, thank you in advance
 

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