Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional statements HELP!!

Status
Not open for further replies.

sstasiak

MIS
Feb 8, 2007
21
US
Hi guys

I'm having some trouble with a database I'm building. I have a form named frmNewPhys that has a text box to input a new physician name into the database, and a button linked to a macro that saves it, updates the physician table, and closes the window.

I'm trying to figure out how I can pop up an error window if someone tries to save with no data in the text box.

I had edited the save button macro to pop up an error form I created. The first line in the macro said "onError" go to next step, where the next step was to open the error form. That seems to work, but the error form still pops up even if data is present in the text box.

I thought an if/else statement would work, but I have no idea how to do this in access. Any help is appreciated.

DB info:

Physician entry form name - 'NewPhysician'
Physician table name - 'Physicians'
Field name in table - 'Physician'
 
How are ya sstasiak . . .

For the textbox have a look at the [blue]BeforeUpdate[/blue] event and its [blue]Cancel[/blue] arguement . . .

Calvin.gif
See Ya! . . . . . .
 
Another idea is to make it impossible for the user to save with no data in the text box by having the form open with the save button NOT enabled. Then:
Code:
Private Sub Form_Dirty(Cancel As Integer)
    
    Me.cmdCancel.Enabled = True
    Me.cmdSave.Enabled = True

End Sub

If you wanted to give the user a chance to save or cancel you could do the following:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.lblSaved.Caption = "WasSaved" Then
    [COLOR=green]'do nothing because user clicked save[/color]

    Else

Dim strMsg As String
    
    strMsg = "Data has changed."
    strMsg = strMsg & vbCrLf & "Do you wish to save your changes?"
    
    If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Changes?") = vbYes Then
        [COLOR=green]'do nothing[/color]
        
    Else
    
    DoCmd.RunCommand acCmdUndo
    
    End If

        Me.LOOKUP.SetFocus
        Me.cmdSave.Enabled = False
        Me.cmdCancel.Enabled = False

End If

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top