Need Existing Info Added to a Form!?!

dgaletar

Registered User.
Local time
Today, 06:09
Joined
Feb 4, 2013
Messages
172
Hello,

I have a form in my database that contains all of the details for a specific vehicle of ours. On that form is a button. In the properties of that button, in the "On Click" event, is an [Event Procedure]. The coding for that [Event Procedure] is as follows:

Code:
Private Sub Command153_Click()
     DoCmd.OpenForm "frmInspection", acNormal, , "[CustomerID]=" & Me.CustomerID, acFormAdd
     Dim f As Form
     Set f = Forms("frmInspection")
        f.CustomerID.DefaultValue = Me.CustomerID
        f.Modal = True
End Sub
As you can see, the button is designed to open a specific form named "Inspection". When it opens that form, it puts the "CustomerID" in the proper place, as the forms are linked that way.

My issue is that I need it to ALSO put in (or populate) the "AltID" for that same vehicle. It seems easy, but for some reason I can't get it to work properly.

Any ideas???

Thx!

DG
 
f.CustomerID.DefaultValue = Me.CustomerID

I take it that "f.CustomerID" points to a combobox?
 
Is "AltID" a control?
 
If your form was bound then this would happen automatically.
But first maybe you should answer Uncle Gizmo first.
 
Um, I don't think that it is a combobox, & no, "AltID" is not a control. It is the alternate ID for the vehicle.

UNCLE GIZMO:
OK, I idouble checked and, no, it is NOT a combobox. It is a textbox.

And, actually, I was wrong on the second question as well. "AltID" IS a control. The control source is "AltID" from the Form "Inspection".

Sorry for the confusion!!! :)

RAINLOVER:
That's why I'm confused. It is bound, and it is not happening. I must have set up something wrong! :(
 
Last edited:
Have you tried:

Code:
     Set f = Forms("frmInspection")
        f.CustomerID.DefaultValue = Me.CustomerID
        f.AltID.DefaultValue = Me.AltID
        f.Modal = True
 
OK, I just tried that, and I got the following:

Compile error:
Method or data member not found
The line "Private Sub Command153_Click()" turns yellow, and the last ".AltID" in the line " f.AltID.DefaultValue = Me.AltID" is highlighted.
 
Your terminology is probably xxx'ed

Control is a "Thing" on a form/Report like textbox, combobox, check box...
Field is part of a record which stems from atable or query
A control can have a field as control source

Is AltID a control or not?
 
Arghhhh!!! I don't know!!! "AltID" is a... a... a...

OK. Here's what I did...

A control can have a field as control source:

When I added "AltID" (as an afterthought), I added a textbox to the form & report. Then, in that texboxes' "Control Source, I used the "AltID" field that I also added to the "Inspection" table.

Does that make any sense???
 
No. What is the name of the textbox?
 
Create two forms form1 and form2. On form1 put a command button and have the command button call this code:

Code:
DoCmd.OpenForm "form2", acNormal
     
     With Forms("Form2")
        .txtID = 3
        .Modal = True
    End With

On form2 put a text box called txtID and when you call the code from form1 it will open form2 and fill txtID with 3

That should give you a start on working out what's wrong with the situation you've got at the moment.
 
OK Uncle Gizmo, I did that. And I think that I understand how what you gave me works. When you open Form2, it populates the "textID" textbox with the number 3.

So now my question is, what if I wanted to instead populate the "textID" textbox with a value that was on Form1? For example, if I had a textbox on Form1 that may hold a value (like 3), how would I get that information to populate the "textID" box on Form2?

WAIT! Don't answer that question! I just figured it out! I put a textbox on Form1 and called it "textID1". I then changed your code to read as follows:

Code:
Private Sub Command2_Click()
DoCmd.OpenForm "form2", acNormal
     
     With Forms("Form2")
        .txtID = TextID1
        .Modal = True
    End With
    End Sub
I then typed "Jack" in Form1. And, when I clicked on the button, Form2 opened with the name "Jack" being displayed.

So now the next step... when I tried to transfer that code over to the actual form that I have been working on (frmInspection), I did it as so:

Code:
'INSPECTION FORM'
Private Sub Command153_Click()
     DoCmd.OpenForm "frmInspection", acNormal, , "[CustomerID]=" & Me.CustomerID, acFormAdd
'     Dim f As Form
'Set f = Forms("frmInspection")
        
     With Forms("frmInspection")
        .CustomerID.DefaultValue = Me.CustomerID
        .AltID.DefaultValue = Me.AltID
        .Modal = True
    End With
        
'        f.CustomerID.DefaultValue = Me.CustomerID
'        f.AltID.DefaultValue = Me.AltID
'        f.Modal = True
End Sub
...and got the "Compile error" again with the Me not highlighted, and the .AltID highlighted.

So I ask again, what am I doing wrong here??? :banghead:

(By the way, I'm frustrated with me... NOT you! I really appreciate your assistance!!! Thx)

WAIT AGAIN! Don't answer that question! I just figured it out again, but this time for real!!!

What I did was this:

Code:
'INSPECTION FORM'
Private Sub Command153_Click()
     DoCmd.OpenForm "frmInspection", acNormal, , "[CustomerID]=" & Me.CustomerID, acFormAdd
   'Manipulate the form
     Dim f As Form
     Set f = Forms("frmInspection")
'    'Set defaultvalue so that all records automatically get assigned the new id
        f.CustomerID.DefaultValue = Me.CustomerID
   'Set the form to be modal. This will prevent the user from clicking outside the form, until the form is closed again.
        f.Modal = True
     With Forms("frmInspection")
        .AltID = Me.AlternateID
        .Modal = True
    End With
End Sub

...the problem, as I figured it out to be, was two fold:

  1. What I was calling ".AltID" on one form was actually ".AlternateID" on another, so I changed the coding to match that.
  2. I also went back to the original coding that worked for the ".CustomerID" but not for the ".AltID", and then just added your coding in after that (but before the "End Sub"), like this:
    Code:
         With Forms("frmInspection")
            .AltID = Me.AlternateID
            .Modal = True
        End With
...and PRESTO!!! It worked!!!

Thanks for the prompting! I really learned something here!


Good luck!
 
Last edited:

Users who are viewing this thread

Back
Top Bottom