AccessWillKill
Registered User.
- Local time
- Today, 20:02
- Joined
- Oct 2, 2010
- Messages
- 50
Hello,
I've been creating a new database and the users have asked for unbound forms to be used. This means i'm passing variables into forms using DLookup and SQL strings.
The one i'm currently on is a form which needs to check the table it would normally be referencing, see if a log exists from the number passed from a different form and then fill all the fields (naming conventions the same as that of the table) with the relevent data from the table.
I've successfuly managed to pass from form to form however from form to table has left me with a problem. i used a Dlookup a for loop and a variable to basically cycle through the forms controls exclude things like labels and then inputs the field data into the relevent field. However rather than put in the data, it is simply putting in the name of the field.
so where say Person Name = Jeff it appears as Person name = Person name on the form.
It is the variable causing the problem but i don't know why and i don't know how to fix it so it gets the field value rather than the field name.
my code is below
I've been creating a new database and the users have asked for unbound forms to be used. This means i'm passing variables into forms using DLookup and SQL strings.
The one i'm currently on is a form which needs to check the table it would normally be referencing, see if a log exists from the number passed from a different form and then fill all the fields (naming conventions the same as that of the table) with the relevent data from the table.
I've successfuly managed to pass from form to form however from form to table has left me with a problem. i used a Dlookup a for loop and a variable to basically cycle through the forms controls exclude things like labels and then inputs the field data into the relevent field. However rather than put in the data, it is simply putting in the name of the field.
so where say Person Name = Jeff it appears as Person name = Person name on the form.
It is the variable causing the problem but i don't know why and i don't know how to fix it so it gets the field value rather than the field name.
my code is below
Code:
For FillRecords = 0 To Forms!SubFrmAdverseEvents.Count - 1
Debug.Print Forms!SubFrmAdverseEvents.Controls(FillRecords).Name
'prevents from filling records with labels
If Not (TypeOf Forms!SubFrmAdverseEvents.Controls(FillRecords) Is Label) Then
'prevents from filling records with Buttons
If Not (TypeOf Forms!SubFrmAdverseEvents.Controls(FillRecords) Is CommandButton) Then
If Not (TypeOf Forms!SubFrmAdverseEvents.Controls(FillRecords) Is SubForm) Then
If Forms!SubFrmAdverseEvents.Controls(FillRecords).Visible = True Then
'this should only leave the table data itself to fill in fields
Debug.Print Forms!SubFrmAdverseEvents.Controls(FillRecords).Name
AEEntityName = Forms!SubFrmAdverseEvents.Controls(FillRecords).Name
Debug.Print AEEntityName
Debug.Print Forms!SubFrmAdverseEvents.Controls(FillRecords).Value
' finally sends the field to the relevent field on the edit form
Forms!SubFrmAdverseEvents.Controls(FillRecords).Value = Nz(DLookup(" '" & AEEntityName & "' ", "tblAE", " AEnumber = " & Forms!SubFrmAdverseEvents.AENumber & " "))
Debug.Print Forms!SubFrmAdverseEvents.Controls(FillRecords)
Debug.Print Forms!SubFrmAdverseEvents.AENumber.Value
End If
End If
End If
End If
'continues the loop
Next FillRecords
Status = Not Status