Inserting info into fields

highland

Registered User.
Local time
Today, 21:15
Joined
Sep 14, 2004
Messages
12
I'm creating a small database which holds information about Grants. I have built a form and created reports which act as confirmation letters.
The Reports use Communication fields as their address.
I would like to populate the Communication fields with data already on the form in other fields when the button is pressed.

Commication fields //// Proposed Matched fields

Communication_Name ///// Applicant_Name
Communication_Address1 ///// Property_Address1
Communication_Address2 ///// Property_Address2
Communication_Address3 ///// Property_Address3
Communication_Address4 ///// Property_Address4
Communication_Address5 ///// Property_Address5

I had tried making these a default in the AfterUpdate event e.g.

If IsNull(me!Communication_Name) then me!Communication_Name = me!Applicant_Name

But this left the Communication_Name field blank - I'm not sure why? :confused:

I would prefer to use a Button control rather than set the default - can anyone help?

Thanks
Suze
 
I would place the code in the Applicant_Name afterUpDate event.

Would this work?
kh
 
Thanks for your reply. ;)
Its not filling the field in - but now its saying it can't find a macro, which isn't surprising because I haven't built one (and I'm not sure how)
 
Problem solved - took a while and a wee bit of a search.
I've managed to use a button to act as a default when pressed.
Theres probably a better way of doing this but it works. ;)

Private Sub Cmd_X_Click()
''Cmd-X is the name of the default button for inputting details in fields
On Error GoTo Err_Cmd_X_Click

If IsNull(Me![Communication_Name]) Then
Me![Communication_Name] = Me![Applicant_Name]
Else
End If

If IsNull(Me![Communication_Address1]) Then
Me![Communication_Address1] = Me![Property_Name]
Else
End If

If IsNull(Me![Communication_Address2]) Then
Me![Communication_Address2] = Me![Property_Address1]
Else
End If

If IsNull(Me![Communication_Address3]) Then
Me![Communication_Address3] = Me![Property_Address2]
Else
End If

If IsNull(Me![Communication_Address4]) Then
Me![Communication_Address4] = Me![Property_Address3]
Else
End If

If IsNull(Me![Communication_Address5]) Then
Me![Communication_Address5] = Me![Property_Address4]
Else

End If
Exit_Cmd_X_Click:
Exit Sub

Err_Cmd_X_Click:
MsgBox Err.Description
Resume Exit_Cmd_X_Click
End Sub
 
Problem even more solved... ;)

Code:
Private Sub Cmd_X_Click()

    On Error GoTo Err_Cmd_X_Click

    Dim intCounter As Integer
    
    If IsNull(Me.[Communication_Name]) Then
        Me.[Communication_Name] = Me.[Applicant_Name]
    End If
    
    For intCounter = 1 To 5
        If intCounter = 1 Then
            If IsNull(Me("Communication_Address" & intCounter)) Then
                Me("Communication_Address1" & intCounter) = Me.[Property_Name]
            End If
        Else
            If IsNull(Me("Communication_Address" & intCounter)) Then
                Me("Communication_Address" & intCounter) = Me("Property_Address" & intCounter - 1)
            End If
        End If
    Next intCounter

End If
Exit_Cmd_X_Click:
    Exit Sub

Err_Cmd_X_Click:
    MsgBox Err.Description
    Resume Exit_Cmd_X_Click
End Sub
 
Thanks for your reply. ;)
I've had a go at putting your code in the database (looks alot less messy than mine) but I've been getting an error message.
When I click the button I get an error message saying 'Compile Error: End If without block If'
It highlights the End If in red below. But if this is removed the button doesn't work, have I managed to miss something in the code? :confused:

Private Sub Cmd_X_Click()

On Error GoTo Err_Cmd_X_Click

Dim intCounter As Integer

If IsNull(Me.[Communication_Name]) Then
Me.[Communication_Name] = Me.[Applicant_Name]
End If

For intCounter = 1 To 5
If intCounter = 1 Then
If IsNull(Me("Communication_Address" & intCounter)) Then
Me("Communication_Address1" & intCounter) = Me.[Property_Name]
End If
Else
If IsNull(Me("Communication_Address" & intCounter)) Then
Me("Communication_Address" & intCounter) = Me("Property_Address" & intCounter - 1)
End If
End If
Next intCounter

End If
Exit_Cmd_X_Click:
Exit Sub

Err_Cmd_X_Click:
MsgBox Err.Description
Resume Exit_Cmd_X_Click
End Sub
 

Users who are viewing this thread

Back
Top Bottom