borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (How can I hide a column in a DataGrid?)Next Topic (problem with MSDE2000 and SQL 2003) New Topic New Poll Post Reply
AndreaVB Forum : Database : How do I store form data to db? Solved Topic
Poster Message
ba1959nh
Level: Scholar

Registered: 10-05-2006
Posts: 39

icon How do I store form data to db?

I have an Access 2003 Form using VB.  This Form contains all of the data for a *new* Supporter Record for my Supporters db table.  I have code to assign the data in the Form's controls into appropriate VB variables (strings, integers) and have confirmed that the assignments work when I click my SAVE button.  
I am now trying to write this new record to the db. I have constructed an INSERT INTO command string (strSQL), but do NOT know how to make the command EXECUTE from inside my VB StoreSupporterData function.

Private Sub fnSaveSupporterRecord()

Dim sSupporterName As String
Dim sOranizationName As String
Dim sAddr1 As String
Dim sAddr2 As String
Dim sCity As String
Dim sState As String
Dim sZip As String
Dim sPhone As String
Dim sFax As String
Dim sEmail As String
Dim sWebsite As String
Dim intOrgType As Integer
Dim intSupporterType As Integer
Dim intSupporterLevel As Integer
Dim intAGWTMembershipID As Integer
Dim bActive As Boolean
Dim sNotes As String


sSupporterName = txtSupporterName
sOranizationName = txtOrganizationName
sAddr1 = txtAddr1
sAddr2 = txtAddr2
sCity = txtCity
sState = ComboState
sZip = txtZip
sPhone = txtPhone
sFax = txtFax
sEmail = txtEmail
sWebsite = txtWebSite
intOrgType = ComboOrgType
intSupporterType = ComboSupporterType
intSupporterLevel = ComboSupporterLevel
intAGWTMembershipID = 0
bActive = true
sNotes = txtNotes

sSQLcmd = "INSERT INTO Supporters (SupporterName, Company_Org_Name, Addr1, Addr2, City, State, Zip, Phone, Fax, Email, WebSite, OrgType, SupporterType, SupporterLevel, AGWTMembershipID, Active, Notes) VALUES ('" & sSupporterName & "', '" & sOranizationName & "', '" & sAddr1 & "', '" & sAddr2 & "', '" & sCity & "', '" & sState & "', '" & sZip & "', '" & sPhone & "', '" & sFax & "', '" & sEmail & "', '" & sWebsite & "', '" & intOrgType & "', '" & intSupporterType & "', '" & intSupporterLevel & "', '" & intAGWTMembershipID & "', '" & bActive & "', '" & sNotes & "');"

' COMMENT - How do I execute this sql comand

End Sub


I appreciate any help.
Thanks,
Bill

[Edited by ba1959nh on 15-05-2006 at 05:09 AM GMT]

15-05-2006 at 05:08 AM
View Profile Send Email to User Show All Posts | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1617
icon Re: How do I store form data to db?

Different ways....

but generally you have to have a connection to the database, then it's like connection_variable.execute sqlstatement [although can be done differently].

____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)

15-05-2006 at 01:18 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
ba1959nh
Level: Scholar

Registered: 10-05-2006
Posts: 39
icon Re: How do I store form data to db?

Any idea where I might find an example?
I have looked in the microsoft help and have not found anything helpful.

15-05-2006 at 02:10 PM
View Profile Send Email to User Show All Posts | Quote Reply
GeoffS
Level: VB Lord


Registered: 29-09-2004
Posts: 536
icon Re: How do I store form data to db?

Hi,
You say that you have this code for an Access 2003 Form - does that mean that you are storing the data in a Table in the Access Database that contains this Form ?
If that is the case then all you need to add at the end of your code is :-

DoCmd.RunSQL sSQLcmd



____________________________
multi-tasking - the ability to hang more than one app. at the same time.

15-05-2006 at 03:33 PM
View Profile Send Email to User Show All Posts | Quote Reply
Gary
Level: Sage

Registered: 27-11-2005
Posts: 50
icon Re: How do I store form data to db?

Hey dude,

I'm using this way to update my data and I just set it as ADODC.recordsource = "sql query here (INSERT INTO...)"

By the way, I'm wondering how come once I click Save, it won't save, I have to click the Add New button, then it will save successfully.


Gary

12-10-2006 at 09:57 AM
View Profile Send Email to User Show All Posts | Quote Reply
ba1959nh
Level: Scholar

Registered: 10-05-2006
Posts: 39
icon Re: How do I store form data to db?

I got this working using the code that GeoffS posted.

DoCmd.RunSQL sSQLcmd


I marked it as Solved back then I thought.
Anyway......it is working now.







12-10-2006 at 06:05 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : Database : How do I store form data to db? Solved Topic
Previous Topic (How can I hide a column in a DataGrid?)Next Topic (problem with MSDE2000 and SQL 2003) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder