Null values in combos

G

Guest

Within an application to keep track of clinical information about patients
there is a registration form that, as well as recording demographic
information about an individual, also records their general practitioner (GP)
and the office address.

The form has, as its record source, tblPatients and the GP selection is made
via a combo box. Record source for the combo is GPID and the row source is a
query based on tblGenPracs. Code in the AfterUpdate event selects the GP’s
office.

My problem is that, unless a GP is selected, the registration form and all
other forms for that patient become blank or only the form detail section of
the registration form is shown, making it necessary to go into design view
and alter the tables directly. I have got round this problem by using a dummy
GP name and address when the GP name is unknown, but I would be most grateful
for advice on how to include null values within the combo boxes without
crashing the application.
 
N

NoodNutt

G'day Sandy

Is your Combo "LimitToList" set at Yes or No. if Yes, then set it to No.

HTH
Mark.
 
M

missinglinq via AccessMonster.com

My programming has always been in a healthcare environment and this type of
problem arises from time to time. The obvious answer is that no patient
should be in the system unless their GP is known, provided they have one,
which is not always true! My solution to the problem was similar to yours,
having a record in my physicians' table for "None/Unknown" which allows the
work to go forward, while letting the staff know that the GP is not known and
should be entered if the info becomes available. The other problem we run
into in Home Health is when there appears to be no "Ordering Physician." This
field HAS
to be required, as it's obviously illegal to be providing services without a
valid order from a physician! It's amazing how quickly we went from only
having an ordering physician about 50% of the time to ALWAYS having one, when
the powers that be understood we couldn't fulfill an order without it!

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
N

NoodNutt

G'day again Sandy

Just remembered 2 handy peices of code.

1. will allow you to enter any patients previous doctor's name into the
combo, if it does not match what you have in your doctors table it will
allow you to include it automatically, you can then enter all the doctors
information in the table later. 2. will auto case what you write.
'
Private Sub DrName_NotInList(NewData As String, Response As Integer)

Dim db As Database, rs As Recordset, strMsg As String

strMsg = NewData & " is not listed ! Do you want to add Him/Her to the
list?"
If MsgBox(strMsg, vbQuestion + vbYesNo, "Add New Doctor ?") = vbNo Then
Response = acDataErrContinue
Else
Set db = CurrentDb()
Set rs = db.OpenRecordset("YourDoctorsTable", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!TheDrName = NewData
rs!TheDrName = MixedCase(TheDrName) *********
rs.Update
If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
End If
Me.Form.Refresh
End Sub

*********
Add the MixedCase Function in a module call it what you like, I use
MixedCase (Go figure :) ) p.s. (Don't include * in your code above)


Copy & Paste the whole thing into the module including the original creators
details

'************** Code Start *************
'This code was originally written by Jay Holovacs.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Jay Holovacs
'
Public Function Mixed_Case(str As Variant) As String
'returns modified string, first character of each word us uppercase
'all others lower case
Dim ts As String, ps As Integer, char2 As String
If IsNull(str) Then
Mixed_Case = ""
Exit Function
End If
str = Trim(str) 'added 11/22/98
If Len(str) = 0 Then
Mixed_Case = ""
Exit Function
End If
ts = LCase$(str)
ps = 1
ps = first_letter(ts, ps)
special_name ts, 1 'try to fix the beginning
Mid$(ts, 1) = UCase$(Left$(ts, 1))
If ps = 0 Then
Mixed_Case = ts
Exit Function
End If
While ps <> 0
If is_roman(ts, ps) = 0 Then 'not roman, apply the other rules
special_name ts, ps
Mid$(ts, ps) = UCase$(Mid$(ts, ps, 1)) 'capitalize the first
letter
End If
ps = first_letter(ts, ps)
Wend
Mixed_Case = ts
End Function
Private Sub special_name(str As String, ps As Integer)
'expects str to be a lower case string, ps to be the
'start of name to check, returns str modified in place
'modifies the internal character (not the initial)

Dim char2 As String
char2 = Mid$(str, ps, 2) 'check for Scots Mc
If (char2 = "mc") And Len(str) > ps + 1 Then '3rd char is CAP
Mid$(str, ps + 2) = UCase$(Mid$(str, ps + 2, 1))
End If

char2 = Mid$(str, ps, 2) 'check for ff
If (char2 = "ff") And Len(str) > ps + 1 Then 'ff form
Mid$(str, ps, 2) = LCase$(Mid$(str, ps, 2))
End If

char2 = Mid$(str, ps + 1, 1) 'check for apostrophe as 2nd char
If (char2 = "'") Then '3rd char is CAP
Mid$(str, ps + 2) = UCase$(Mid$(str, ps + 2, 1))
End If

Dim char3 As String
char3 = Mid$(str, ps, 3) 'check for scots Mac
If (char3 = "mac") And Len(str) > ps + 1 Then 'Mac form
Mid$(str, ps + 3) = UCase$(Mid$(str, ps + 3, 1))
End If

Dim char4 As String
char4 = Mid$(str, ps, 4) 'check for Fitz
If (char4 = "fitz") And Len(str) > ps + 1 Then 'Fitz form
Mid$(str, ps + 4) = UCase$(Mid$(str, ps + 4, 1))
End If

End Sub
Private Function first_letter(str As String, ps As Integer) As Integer
'ps=starting point to search (starts with character AFTER ps)
'returns next first letter, 0 if no more left
'modified 6/18/99 to handle hyphenated names
Dim p2 As Integer, p3 As Integer, s2 As String
s2 = str
p2 = InStr(ps, str, " ") 'points to next blank, 0 if no more
p3 = InStr(ps, str, "-") 'points to next hyphen, 0 if no more
If p3 <> 0 Then
If p2 = 0 Then
p2 = p3
ElseIf p3 < p2 Then
p2 = p3
End If
End If
If p2 = 0 Then
first_letter = 0
Exit Function
End If
'first move to first non blank, non punctuation after blank
While is_alpha(Mid$(str, p2)) = False
p2 = p2 + 1
If p2 > Len(str) Then 'we ran off the end
first_letter = 0
Exit Function
End If
Wend
first_letter = p2
End Function
Public Function is_alpha(ch As String)
'returns true if this is alphabetic character
'false if not
Dim C As Integer
C = Asc(ch)
Select Case C
Case 65 To 90
is_alpha = True
Case 97 To 122
is_alpha = True
Case Else
is_alpha = False
End Select

End Function
Private Function is_roman(str As String, ps As Integer) As Integer
'starts at position ps, until end of word. If it appears to be
'a roman numeral, than the entire word is capped in passed back
'string, else no changes made in string
'returns 1 if changes were made, 0 if no change
Dim mx As Integer, p2 As Integer, flag As Integer, I As Integer
mx = Len(str) 'just so we don't go off the edge
p2 = InStr(ps, str, " ") 'see if there is another space after this word
If p2 = 0 Then
p2 = mx + 1
End If
'scan to see if any inappropriate characters in this word
flag = 0
For I = ps To p2 - 1
If InStr("ivxIVX", Mid$(str, I, 1)) = 0 Then
flag = 1
End If
Next I
If flag Then
is_roman = 0
Exit Function 'this is not roman numeral
End If
Mid$(str, ps) = UCase$(Mid$(str, ps, p2 - ps))
is_roman = 1
End Function
'************** Code End *************

Once this code is in place you can call on it to auto case any written text
in a field.

Have fun

Regards
Mark.
 
G

Guest

G'day Mark

Thanks very much for your help and for all the code. I do have a routine
that makes it possible to add a GP +/- office by double clicking on the
combo, but the problem arises when the GP isn't known. Although having a
dummy GP or 'Unknown' works, it's not very elegant and it should be possible
for the combo to be blank. The lack of a GP would then be trapped when an
attempt to send a letter to the non-existent GP was made.

Regards

Sandy
 

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