not good with VBA (1 Viewer)

aftershokk

Registered User.
Local time
Today, 07:33
Joined
Sep 5, 2001
Messages
259
currently I have a form (based on table) with specialties listed with check boxes next to each label

example:
cardiology, check box
GI, check :confused:box
etc...

Currently, the user clicks the Cardiology check box and then hits the command button which runs a macro that will open the report. I want to modify the code to pick one report if only certain boxes are checked and if any of the others are listed it will run a different report.

example: if cardiology or GI or IM etc. is checked run report x macro otherwise report y macro

current code below;

Private Sub convert_to_pdf_button_Click()
On Error GoTo Err_convert_to_pdf_button_Click

Dim stDocName As String

stDocName = "redesign_send"
DoCmd.RunMacro stDocName

Exit_convert_to_pdf_button_Click:
Exit Sub

Err_convert_to_pdf_button_Click:
MsgBox Err.Description
Resume Exit_convert_to_pdf_button_Click

End Sub

thanks
 

Kiwiman

Registered User
Local time
Today, 07:33
Joined
Apr 27, 2008
Messages
799
Howzit

One way of doing this would be something like...

Code:
Private Sub convert_to_pdf_button_Click()
On Error GoTo Err_convert_to_pdf_button_Click

Dim stDocName As String

If me.cardiology = -1 or me.GI = -1 (and so on) Then
stDocname = "Macro X"
else
stdocname = "Macro y"
end if


docmd.runmacro stDocName

Exit_convert_to_pdf_button_Click:
Exit Sub

Err_convert_to_pdf_button_Click:
MsgBox Err.Description
Resume Exit_convert_to_pdf_button_Click

End Sub
 

fezzzz

New member
Local time
Today, 02:33
Joined
Feb 3, 2009
Messages
1
This should help! just change the checkbox names.
If you want to check multiple check boxes then use "and" statements with the if's.

Private Sub convert_to_pdf_button_Click()
On Error GoTo Err_convert_to_pdf_button_Click

Dim stDocName As String

if me.Cardiololgycheckboxname.value = true then
stDocName = "redesign_send_Cardiology"
elseif me.GICheckBoxName.Value = True Then
stDocName = "redesign_send_GI"
ElseIf me.IMCheckBoxName.Value = True Then
stDocName = "redesign_send_IM"
End if

if stDocName <> "" then
DoCmd.RunMacro stDocName
end if

Exit_convert_to_pdf_button_Click:
Exit Sub

Err_convert_to_pdf_button_Click:
MsgBox Err.Description
Resume Exit_convert_to_pdf_button_Click

End Sub
 

aftershokk

Registered User.
Local time
Today, 07:33
Joined
Sep 5, 2001
Messages
259
Hi, thanks for the responses but let me clarify some more.

The form has 2 fields. One called type_name (list of medical specialties) and one each specialty has a check box (report_indicator) :confused:next to it. I need something like this below but it does not work.

Private Sub convert_to_pdf_button_Click()
On Error GoTo Err_convert_to_pdf_button_Click

Dim stDocName As String

If report_indicator = -1 And type_name = "Internal Medicine" or
report_indicator = -1 And type_name = "GI" or
report_indicator = -1 And type_name = "Pedi"
Then
stDocName = "redesign_send"
Else

stDocName = "scp_send"
DoCmd.RunMacro stDocName
End If

Exit_convert_to_pdf_button_Click:
Exit Sub

Err_convert_to_pdf_button_Click:
MsgBox Err.Description
Resume Exit_convert_to_pdf_button_Click
 

Users who are viewing this thread

Top Bottom