Link to home
Start Free TrialLog in
Avatar of military donut
military donutFlag for United States of America

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.
ASKER CERTIFIED SOLUTION
Avatar of James Elliott
James Elliott
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of military donut

ASKER

Expected end of statement

but changed to this...and works perfectly.

Thanks!
Avatar of 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