Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2009
    Posts
    2

    Unanswered: I am trying to write data to table

    Hi All

    I am currently building a database for work.

    I am trying to write some data to a table when certain command buttons are being pushed here is a code I have so far.

    Public Sub WriteToLogtbl(strMessage As String)

    Dim SQL As String

    SQL = ("INSERT INTO logtbl (Current_User, Date, Time) " & _
    " Values (& CurrentUser &, " & Updated quantities for & " & Me!cboResupply, " & Date & ", " & Time & ")")

    End Sub

    This sub is then called in another form to write the data to a table.

  2. #2
    Join Date
    May 2005
    Posts
    1,191
    I'm guessing you're problem then is that you're not sure how to actually execute the SQL string? Take a look at the RunSQL method. And if you need more help with that, I'd recommend Martin Green's tutorial.

    But if I'm way off the mark and answered the wrong question, let me know.
    Me.Geek = True

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    and whilst we are at it, I'd suggest not to use the currerntuser function, instead consider using the API call to get the network logon. if that is of interest to you look in either the code bank or do a google for Dev Asish API
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Mar 2009
    Posts
    2
    Thanks for the info I forgot that I did not tell it to do anything.

    I am still having some syntax errors that I am still fighting with

  5. #5
    Join Date
    May 2005
    Posts
    1,191
    I think I can see at least one problem; you're probably going to need apostrophes to denote strings and pound signs to denote date/times, like:

    Code:
    SQL = "INSERT INTO logtbl (Current_User, Resupply, Date, Time) " & _
         "Values ('" & fosUserName() & "', '" & Me!cboResupply & "', #" & Date & "#, #" & Time & "#)"
    Remember, you need to tell access they're strings and dates (respectively), else it thinks it's an in-built variable or something and can't figure it out.

    A couple of other things:
    • You'll probably also want to change your Date and Time field names to NOT be a reserved word. And you may also want to consider combining these into a single field as it is rather redundant to have two split fields. If you need to display the field as a date and a time seperately, then put the field on your form twice and format it into date and time. Remember, store data not formatting.
    • I'm not sure if you have a Resupply field or not, but I'm guessing you forgot that in the field name list.
    • And, obviously, I agree with healdem on the fosusername() thing.

    Last edited by nckdryr; 03-26-09 at 12:04.
    Me.Geek = True

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •