help writing a code

icemonster

Registered User.
Local time
Today, 16:47
Joined
Jan 30, 2010
Messages
502
can someone tell me what needs to be changed here.

basically, what i want is, if the form is opened through the listbox, it would filter the clientID through the listbox, but if the form is a new record, the sql statement would then be filtered using the forms clientid, here's the code.

Code:
If Not IsNull(Forms![frmMainMenu]![lstPatients]) Then
    lngClientID = Forms![frmMainMenu]![lstPatients]
    'determine if there is any existing value in the "strwheresql" variable
        strWhereSql = "Where qryClientStatusList1.CSCLIENTID = " & lngClientID & " "
    Else
        strWhereSql = ""
End If

If Not IsNull(Forms![frmClientDetails1]![txtClientID]) Then
    lngClientID2 = Forms![frmClientDetails1]![txtClientID]
If strWhereSql = "" Then
        strWhereSql = "Where qryClientStatusList1.CSCLIENTID = " & lngClientID2 & " "
    Else
       strWhereSql = strWhereSql & "And qryClientStatusList1.CSCLIENTID = " & lngClientID2 & " "
    End If
End If
 
You didn't mention what version of Access... I would use the IsLoaded() function...

Code:
If IsLoaded(Forms![frmMainMenu]![lstPatients]) Then
lngClientID = Forms![frmMainMenu]![lstPatients]
Else
lngClientID = Forms![frmClientDetails1]![txtClientID]
End If
However, if there is more then two forms then perhaps a SELECT CASE statement?
 
getting an error, it wants me to define it?
 
To use the built-in IsLoaded function:

If CurrentProject.AllForms("frmMainMenu").IsLoaded Then
 
so it would look like this?

Code:
If CurrentProject.AllForms("frmMainMenu").IsLoaded Then
    If IsLoaded(Forms![frmMainMenu]![lstPatients]) Then
        strWhereSql = "WHERE qryClientStatusList1.CSCLIENTID = " & Forms![frmMainMenu]![lstPatients] & " "
    Else
    strWhereSql = "WHERE qryClientStatusList1.CSCLIENTID = " & Forms![frmClientDetails1]![txtClientID] & " "
    End If
End If

is there any other alternative to open a form with two criteria? 1 being that if the form is opened through a listbox and the other if the form is just opened through a button (as a new record)?
 
Oops, let's fix that...
Code:
If CurrentProject.AllForms("frmMainMenu").IsLoaded Then
    strWhereSql = "WHERE qryClientStatusList1.CSCLIENTID = " & Forms![frmMainMenu]![lstPatients] & " "
Else
    strWhereSql = "WHERE qryClientStatusList1.CSCLIENTID = " & Forms![frmClientDetails1]![txtClientID] & " "
    End If

There are other ways to open a form with multiple criteria but all require code. Is there a reason you don't want to do it this way? Like more then two criteria?
 

Users who are viewing this thread

Back
Top Bottom