Avatar of Ernest Grogg
Ernest Grogg
 asked on

public sub module, passing data to table

Hello,

I would like to use the following sub routine to take data from a field on a form and pass the data to the table:

Public Sub VGTruck(Driver1_FName As String, Driver1_LName As String)
CurrentDb.Execute "INSERT INTO VGTruckProcessing (Driver1_FName, Driver1_LName) Values ('" & Driver1_FName & "','" & Driver1_LName & " ')"

End Sub


This is on my form that I want to pass the data to
trkproc.VGTruck (me.Name1 , me.Name2)

I want the data from the control,  I tried using "Driver1_FName as Control" but that is wrong too.  Don't know what I should use here.
Microsoft AccessVBA

Avatar of undefined
Last Comment
Hamed Nasr

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
James Elliott

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Ernest Grogg

ASKER
Expected end of statement

but changed to this...and works perfectly.

Thanks!
Hamed Nasr

Try:
Module:
Public Sub VGTruck(Driver1_FName As String, Driver1_LName As String)
    CurrentDb.Execute "INSERT INTO  VGTruckProcessing (Driver1_FName, Driver1_LName) 
 Values ( '" & Driver1_FName & "','" & Driver1_LName & "')"
End Sub

Open in new window

Calling from a button in form:
Private Sub Command4_Click()
    VGTruck Me.Driver1_FName , Me.Driver1_LName
End Sub

Open in new window


Above code was  modified from the following tested code using Table1 (Gender, DG)
Form fields are f1, f2.
Module:
Public Sub VGTruck(Driver1_FName As String, Driver1_LName As String)
    CurrentDb.Execute "INSERT INTO Table1 (GENDER, DG) Values ( '" & Driver1_FName & "','" & Driver1_LName & "')"
End Sub

Open in new window

Calling from a button in form:  f1 input value for FName, f2 input value for LName
Private Sub Command4_Click()
    VGTruck Me.f1, Me.f2
End Sub

Open in new window

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy